GUI Slider to Send Keystroke to Application?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SmithyZoomZoom
Posts: 117
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 21 Jan 2022, 17:30

I followed your very helpful instructions and recorded the results in a brief, two-minute video:
https://drive.google.com/file/d/1OhX3eKou9HjRhyIQH4YTqLZG0Hcbb88c/view?usp=sharing

Thanks, again!

User avatar
mikeyww
Posts: 28989
Joined: 09 Sep 2014, 18:38

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 21 Jan 2022, 17:56

I'm not sure what issue might be occurring for you. As noted, it works here. Perhaps others can test as well. I'm on Windows 10 with AHK 1.1.33.10 and MusicBee 3.4.8033 P.

SmithyZoomZoom
Posts: 117
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 26 Jan 2022, 09:50

I do have one potential solution but I am not in a place where I can implement the code yet – just writing down the general idea for later. Here is the thought:

Instead of doing things the Mikey way, which is elegant and awesome and like a real piece of computer code, we do it the SmithyZoomZoom way, which is like banging together two coconuts and hoping a unicorn pops out. In other words, when the rewind/fast-forward buttons are clicked, do a Winactivate of Musicbee and then send the appropriate keystrokes without specifying a target application. Am I making sense on this one?

Also, out of curiosity, Mikey, did you install the music player for troubleshooting purposes with me, or do you use it generally?

User avatar
mikeyww
Posts: 28989
Joined: 09 Sep 2014, 18:38

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 26 Jan 2022, 10:08

Sure, using Send following a WinActivate is often a good approach, especially when ControlSend does not work. In my posts here, I think I actually just used your own original approach.

I have had MusicBee installed for many years, though I do not use it a lot these days. I generally just connect my smartphone (has 3,500 songs) to a Bluetooth speaker.

SmithyZoomZoom
Posts: 117
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 31 Jan 2022, 00:49

3500 songs? Nice. It reminds me of my original MP3 collection from back when I thought Britney Spears was going to be a one-hit-wonder.
(I was never one for predicting trends.)

So I have been fiddling around with the script when I decided to test this:

Code: Select all

ButtonFF:
;~ WinActivate ahk_exe MusicBee.exe
;~ Send '
Tooltip testing
sleep, 5000
Tooltip
Return
I could not even get the tooltip to display upon button press. Peculiar!

I was wondering, would you be so kind as to make a button clicking script that was totally separate from the slider and see if we could at least get stuff to happen when buttons are clicked in a GUI?

Thank you very much for reading!

User avatar
boiler
Posts: 17706
Joined: 21 Dec 2014, 02:44

Re: GUI Slider to Send Keystroke to Application?

Post by boiler » 31 Jan 2022, 03:47

mikeyww wrote: I generally just connect my smartphone (has 3,500 songs) to a Bluetooth speaker.
What a coincidence. I have 3,588 songs on mine.

User avatar
mikeyww
Posts: 28989
Joined: 09 Sep 2014, 18:38

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 31 Jan 2022, 05:26

Good to hear about those MP3 libraries!

Code: Select all

Gui, +AlwaysOnTop
Gui, Color, FFFFC2
Gui, Font, s20 w700
Gui, Add, Text  , x+m ym   w200 Center, 1.00x
Gui, Font, s12 w400
Gui, Add, Button, x+m ym+5 w50        , FF
Gui, Show, x200
Return

ButtonFF:
MsgBox, 64, Status, It worked!
Return

SmithyZoomZoom
Posts: 117
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 31 Jan 2022, 10:13

This works when I put in the fast forward key:

Code: Select all

Gui, +AlwaysOnTop
Gui, Color, FFFFC2
Gui, Font, s20 w700
Gui, Add, Text  , x+m ym   w200 Center, 1.00x
Gui, Font, s12 w400
Gui, Add, Button, x+m ym+5 w50        , FF
Gui, Show, x200
Return

ButtonFF:
ControlSend,, ', ahk_exe MusicBee.exe
MsgBox, 64, Status, It worked!
Return

User avatar
mikeyww
Posts: 28989
Joined: 09 Sep 2014, 18:38

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 31 Jan 2022, 10:22

Problem solved!

SmithyZoomZoom
Posts: 117
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 31 Jan 2022, 15:37

Yes. I'm a little unsure how to incorporate the tempo slider with the playback and fast-forward buttons without everything going to pieces…?

User avatar
mikeyww
Posts: 28989
Joined: 09 Sep 2014, 18:38

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 31 Jan 2022, 15:46

Straightforward: add one line, control, or small section at a time. Retest iteratively along the way.

SmithyZoomZoom
Posts: 117
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 01 Feb 2022, 22:17

Yes, you are correct. That is a good approach. I fiddled around some more and even though the layout is all messed up and strange looking, I did get the buttons to work. Weirdly, now it's the slider that's broken:

Code: Select all

Gui, +AlwaysOnTop
Gui, Color, FFFFC2
Gui, Font, s20 w700
Gui, Add, Text  , x+m ym   w200 Center, 1.00x
Gui, Font, s12 w400
Gui, Add, Button, x+m ym+5 w50        , FF
Gui, Color, FFFFC2
Gui, Font, s12 w400
Gui, Add, Button,       ym+5  w50                      , REW
Gui, Add, Text  ,                                 vt1  , 1.00x
Gui, Add, Text  ,                                 vt2  , 2.00x
Gui, Show, x200
Gui, Add, Slider, xm+40 ys+55 w250 Range0-10 Buddy1t1 Buddy2t2 TickInterval AltSubmit gAdjust vslide, 0
WinSet, Transparent, 200
Loop {
 WinWaitActive, %winTitle%
 Gui, % "+Owner" WinActive()
 Gui, Show, x%x% y%y% h100 NoActivate, Playback speed
 WinWaitNotActive   ; When MusicBee is no longer active,
 Gui, Hide          ;  hide the GUI
}
Adjust:
Gui, Submit, NoHide
GuiControl,, sVal, % Format("{:.2f}x", Round(slide / 10 + 1, 1))
If (A_GuiEvent != "Normal")
 Return
SoundBeep, 1900
ControlSend,, {=}        , %winTitle%
ControlSend,, {] %slide%}, %winTitle%
Return
;~ Gui, Show, x200
;~ Return

ButtonREW:
ControlSend,, _, ahk_exe MusicBee.exe
Return

ButtonFF:
ControlSend,, ', ahk_exe MusicBee.exe
MsgBox, 64, Status, It worked!
Return

User avatar
mikeyww
Posts: 28989
Joined: 09 Sep 2014, 18:38

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 01 Feb 2022, 22:22

Follow the script line by line. Which line defines winTitle?

SmithyZoomZoom
Posts: 117
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 02 Feb 2022, 20:13

Thanks. I was able to get the slider to work by reinserting this at the top:

Code: Select all

winTitle = ahk_class WindowsForms10.Window.8.app.0.2bf8098_r7_ad1 ahk_exe MusicBee.exe


Downside is that there is an invalid options error which is related to line 19. When I close the error message box, the script still works but it does not automatically hide the playback speed window:
https://drive.google.com/file/d/1gbB8W2kE0VnGeItcmZn8YHP945vXs2Bk/view?usp=sharing

When I re-include the line about the GUI coordinates, so that it looks like this:

Code: Select all

winTitle = ahk_class WindowsForms10.Window.8.app.0.2bf8098_r7_ad1 ahk_exe MusicBee.exe
x := 1360, y := 591 ; GUI uses screen coordinates
…the error message disappears. The GUI appears in the proper place on the screen. The GUI hides when the audiobook player is nonactive, like it's supposed to. Sliding the tempo slider changes the speed of playback. However, the fast-forward and rewind buttons stopped working, leaving me confused?

User avatar
mikeyww
Posts: 28989
Joined: 09 Sep 2014, 18:38

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 02 Feb 2022, 20:27

You can post your latest revised script for more feedback about it.

SmithyZoomZoom
Posts: 117
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 03 Feb 2022, 22:34

Thank you. I'm wondering if we could sidestep the mysterious issue by having the tempo slider and fast forward/rewind buttons in separate GUI boxes. Maybe there is something about putting more features in the same window that my computer is grumpy about?

Latest revision:

Code: Select all

winTitle = ahk_class WindowsForms10.Window.8.app.0.2bf8098_r7_ad1 ahk_exe MusicBee.exe
x := 1360, y := 591 ; GUI uses screen coordinates
Gui, +AlwaysOnTop
Gui, Color, FFFFC2
Gui, Font, s20 w700
Gui, Add, Text  , x+m ym   w200 Center, 1.00x
Gui, Font, s12 w400
Gui, Add, Button, x+m ym+5 w50        , FF
Gui, Color, FFFFC2
Gui, Font, s12 w400
Gui, Add, Button,       ym+5  w50                      , REW
Gui, Add, Text  ,                                 vt1  , 1.00x
Gui, Add, Text  ,                                 vt2  , 2.00x
Gui, Show, x200
Gui, Add, Slider, xm+40 ys+55 w250 Range0-10 Buddy1t1 Buddy2t2 TickInterval AltSubmit gAdjust vslide, 0
WinSet, Transparent, 200
Loop {
 WinWaitActive, %winTitle%
 Gui, % "+Owner" WinActive()
 Gui, Show, x%x% y%y% h100 NoActivate, Playback speed
 WinWaitNotActive   ; When MusicBee is no longer active,
 Gui, Hide          ;  hide the GUI
}
Adjust:
Gui, Submit, NoHide
GuiControl,, sVal, % Format("{:.2f}x", Round(slide / 10 + 1, 1))
If (A_GuiEvent != "Normal")
 Return
SoundBeep, 1900
ControlSend,, {=}        , %winTitle%
ControlSend,, {] %slide%}, %winTitle%
Return
;~ Gui, Show, x200
;~ Return

ButtonREW:
ControlSend,, _, ahk_exe MusicBee.exe
Return

ButtonFF:
ControlSend,, ', ahk_exe MusicBee.exe
MsgBox, 64, Status, It worked!
Return

User avatar
mikeyww
Posts: 28989
Joined: 09 Sep 2014, 18:38

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 04 Feb 2022, 08:35

Try this one.

Code: Select all

winTitle = ahk_exe MusicBee.exe
x := 1360, y := 591 ; GUI uses screen coordinates
Gui, +AlwaysOnTop
Gui, Color, FFFFC2
Gui, Font, s20 w700
Gui, Add, Text  , x+m ym   w200 Center, 1.00x
Gui, Font, s12 w400
Gui, Add, Button, x+m ym+5 w50        , FF
Gui, Color, FFFFC2
Gui, Font, s12 w400
Gui, Add, Button,       ym+5  w50                      , REW
Gui, Add, Text  ,                                 vt1  , 1.00x
Gui, Add, Text  ,                                 vt2  , 2.00x
Gui, Show, x200
Gui, Add, Slider, xm+40 ys+55 w250 Range0-10 Buddy1t1 Buddy2t2 TickInterval AltSubmit gAdjust vslide, 0
WinSet, Transparent, 200
Loop {
 WinWaitActive, %winTitle%
 Gui, % "+Owner" WinActive()
 Gui, Show, x%x% y%y% h100 NoActivate, Playback speed
 WinWaitNotActive   ; When MusicBee is no longer active,
 Gui, Hide          ;  hide the GUI
}
Adjust:
Gui, Submit, NoHide
GuiControl,, sVal, % Format("{:.2f}x", Round(slide / 10 + 1, 1))
If (A_GuiEvent != "Normal")
 Return
SoundBeep, 1900
ControlSend,, ={] %slide%}, %winTitle%
Return

ButtonREW:
ControlSend,, _,  %winTitle%
Return

ButtonFF:
ControlSend,, ',  %winTitle%
Return

SmithyZoomZoom
Posts: 117
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 04 Feb 2022, 17:43

Thank you for your latest work! Hmm, I can get the rewind and fast forward features to work along with the tempo using your latest script, but only if I remove the part that automatically hides the window when the audiobook player is not showing, like this:

Code: Select all

winTitle = ahk_exe MusicBee.exe
x := 1360, y := 591 ; GUI uses screen coordinates
Gui, +AlwaysOnTop
Gui, Color, FFFFC2
Gui, Font, s20 w700
Gui, Add, Text  , x+m ym   w200 Center, 1.00x
Gui, Font, s12 w400
Gui, Add, Button, x+m ym+5 w50        , FF
Gui, Color, FFFFC2
Gui, Font, s12 w400
Gui, Add, Button,       ym+5  w50                      , REW
Gui, Add, Text  ,                                 vt1  , 1.00x
Gui, Add, Text  ,                                 vt2  , 2.00x
Gui, Show, x200
Gui, Add, Slider, xm+40 ys+55 w250 Range0-10 Buddy1t1 Buddy2t2 TickInterval AltSubmit gAdjust vslide, 0
WinSet, Transparent, 200
Loop {
 ;~ WinWaitActive, %winTitle%
 ;~ Gui, % "+Owner" WinActive()
 ;~ Gui, Show, x%x% y%y% h100 NoActivate, Playback speed
 ;~ WinWaitNotActive   ; When MusicBee is no longer active,
 ;~ Gui, Hide          ;  hide the GUI
}
Adjust:
Gui, Submit, NoHide
GuiControl,, sVal, % Format("{:.2f}x", Round(slide / 10 + 1, 1))
If (A_GuiEvent != "Normal")
 Return
SoundBeep, 1900
ControlSend,, ={] %slide%}, %winTitle%
Return

ButtonREW:
ControlSend,, _,  %winTitle%
Return

ButtonFF:
ControlSend,, ',  %winTitle%
Return

User avatar
mikeyww
Posts: 28989
Joined: 09 Sep 2014, 18:38

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 04 Feb 2022, 17:53

If you do not need the loop, you can replace it with Return.

SmithyZoomZoom
Posts: 117
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 05 Feb 2022, 15:33

Thank you, sir. The difficulty is that I do need the loop because it would be awesome if the window vanished whenever the audiobook player is not active. I was wondering if there was a way to incorporate the solution offered by Leef_me in the discussion thread here: Hide GUI Window - Ask for Help - AutoHotkey Community
https://www.autohotkey.com/board/topic/68496-hide-gui-window/

(I'm not exactly sure how to do it myself or I would of course give it a try.)

Post Reply

Return to “Ask for Help (v1)”