Microsoft Edge Read Aloud Feature Automation - Speed Slider Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
GabeCalderon
Posts: 7
Joined: 19 Aug 2022, 01:24

Microsoft Edge Read Aloud Feature Automation - Speed Slider

Post by GabeCalderon » 24 Sep 2022, 15:43

Hi,

I am attempting to automate the Slider control for the voice speed within Microsoft Edge Read Aloud Bar's submenu. Image attached. This is built specifically for Edge browser and can be accessed on any webpage by the following shortcut: Ctrl+Shift+U. It is a very nice built-in tool that gives free access to reading text on websites coupled with in-page text highlighting of the current word being read.
image.png
image.png (210.63 KiB) Viewed 826 times
These features can actually be accessed in an isolated environment by going to these URLs:
1) edge://read-aloud-bar/pane
2) edge://read-aloud-bar/bar

I am currently using the UIA library published by Descolada (viewtopic.php?style=2&t=104999) to try and change the value of the slider with no success. It is also very curious that I am able to change the slider position manually with the Left/Right arrow keys, however, when I attempt to do so using SendInput, I do not get any response from the slider.

Here is my current code attempt:

Code: Select all

#Persistent
#NoEnv
#SingleInstance, Force
SendMode Input
SetTitleMatchMode 2
SetWorkingDir, %A_ScriptDir%
#include %A_ScriptDir%/UIAutomation/Lib
#include UIA_Interface.ahk

initializeUIA()


; MANUALLY OPEN THE READ ALOUD BAR USING CTRL+SHIFT+U (I have written a script to automate this process and check for when the read aloud bar is present, but it is not pertinent to my current issue so was not included.)
g::
openMsReadAloudSubmenu()
return

h::
changeMsReadAloudSpeed()
return

initializeUIA() {
    global UIA
    UIA := UIA_Interface() ; Initialize UIA interface
    global UIA_Edge_Element
    UIA_Edge_Element := UIA.ElementFromHandle(WinExist("ahk_class Chrome_WidgetWin_1 ahk_exe msedge.exe")) ; Get the element for the target window
}


openMsReadAloudSubmenu() {
    global UIA_Edge_Element
    voice_options_button := UIA_Edge_Element.FindFirstByNameAndType("Read aloud", "Document").FindFirstByNameAndType("Voice options", "Button")
    voice_options_button.Click()
}

changeMsReadAloudSpeed() {
    global UIA_Edge_Element
    voice_options_button := UIA_Edge_Element.FindFirstBy("ClassName=RootView AND LocalizedControlType=dialog").FindFirstByNameAndType("Read aloud", "Document").FindFirstByType("Group").FindByPath("1.2")
    voice_options_button.SetFocus()
    voice_options_button.SetValue(2) ; does not work
    voice_options_button.GetCurrentPatternAs("LegacyIAccessible").SetValue(2) ; does not work
    SendInput, {Right} ; does not work, but if you manually press the right arrow button, the slider value changes.
}


BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Microsoft Edge Read Aloud Feature Automation - Speed Slider

Post by BoBo » 24 Sep 2022, 23:53

Probably @malcev's solution from here: viewtopic.php?p=482885#p482885 :?:

User avatar
GabeCalderon
Posts: 7
Joined: 19 Aug 2022, 01:24

Re: Microsoft Edge Read Aloud Feature Automation - Speed Slider

Post by GabeCalderon » 25 Sep 2022, 00:19

BoBo wrote:
24 Sep 2022, 23:53
Probably @malcev's solution from here: viewtopic.php?p=482885#p482885 :?:
I saw this answer by @malcev but I did not know how to apply it given that the slider in question has no direct control listed within WinSpy.
image.png
image.png (272.37 KiB) Viewed 751 times

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Microsoft Edge Read Aloud Feature Automation - Speed Slider

Post by malcev » 25 Sep 2022, 00:45

No. Chrominium does not use standard controls, even tooltips or any other onscreen information - are all custom windows.
You can set focus with iaccessible or with uia to slider and move it with arrows, or just send controlclick to needed position without focusing.

User avatar
GabeCalderon
Posts: 7
Joined: 19 Aug 2022, 01:24

Re: Microsoft Edge Read Aloud Feature Automation - Speed Slider

Post by GabeCalderon » 25 Sep 2022, 14:20

malcev wrote:
25 Sep 2022, 00:45
No. Chrominium does not use standard controls, even tooltips or any other onscreen information - are all custom windows.
You can set focus with iaccessible or with uia to slider and move it with arrows, or just send controlclick to needed position without focusing.
@BoBo
@malcev would you happen to know why I can move the slider manually with Left/Right arrows, but I cannot do so using SendInput? I am certain that I have focused on the slider (because the Slider circle gets highlighted), but for some reason, SendInput with {Left} and {Right} have no effect. It would be a solution if someone could help me figure out what I need to do in order for the Speed Slider to respond to my SendInputs with the Left/Right arrows.

User avatar
GabeCalderon
Posts: 7
Joined: 19 Aug 2022, 01:24

Re: Microsoft Edge Read Aloud Feature Automation - Speed Slider

Post by GabeCalderon » 25 Sep 2022, 16:19

Just in case it is pertinent to helping me solve my issue with SendInput arrow keys not working to move the Speed Slider position... This is an example of the visual cue that I receive to let me know that the Slider has focus:
image.png
image.png (22.68 KiB) Viewed 677 times

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Microsoft Edge Read Aloud Feature Automation - Speed Slider  Topic is solved

Post by malcev » 25 Sep 2022, 21:42

You can try to add sleep.

Code: Select all

Send {right down}
sleep 200
Send {right up}

User avatar
GabeCalderon
Posts: 7
Joined: 19 Aug 2022, 01:24

Re: Microsoft Edge Read Aloud Feature Automation - Speed Slider

Post by GabeCalderon » 25 Sep 2022, 22:37

malcev wrote:
25 Sep 2022, 21:42
You can try to add sleep.

Code: Select all

Send {right down}
sleep 200
Send {right up}
The simplest things I swear :crazy:! Thanks @malcev, that worked perfectly!

Descolada
Posts: 1099
Joined: 23 Dec 2021, 02:30

Re: Microsoft Edge Read Aloud Feature Automation - Speed Slider

Post by Descolada » 25 Sep 2022, 23:17

@GabeCalderon, it does seem that the speed sliders' value cannot be changed via ValuePattern nor RangeValuePattern. ValuePattern does report the actual current value though, so you can use that in combination with sending left-right buttons to get the correct speed. ControlClick works as well after setting a delay with Sleep or SetKeyDelay:

Code: Select all

#include <UIA_Interface>
UIA := UIA_Interface()
WinActivate, ahk_exe msedge.exe
WinWaitActive, ahk_exe msedge.exe
edge := UIA.ElementFromhandle("ahk_exe msedge.exe")
edge.FindFirstBy("Name=Voice options and Type=Button").Click()
slider := edge.WaitElementExist("Name=Speed and Type=Slider")
slider.SetFocus()
prevValue := slider.Value
SetKeyDelay, 0, 100
ControlSend,, {Left}, ahk_exe msedge.exe
MsgBox, % "Value before: " prevValue "`nAfter moving: " slider.Value
I recommend filing a bug report with Microsoft as well about the non-functioning RangeValuePattern, because they do seem to care about UIAutomation and might fix it.

Post Reply

Return to “Ask for Help (v1)”