GUI Slider to Send Keystroke to Application?
-
- Posts: 117
- Joined: 23 Aug 2019, 23:32
Re: GUI Slider to Send Keystroke to Application?
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!
https://drive.google.com/file/d/1OhX3eKou9HjRhyIQH4YTqLZG0Hcbb88c/view?usp=sharing
Thanks, again!
Re: GUI Slider to Send Keystroke to Application?
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.
-
- Posts: 117
- Joined: 23 Aug 2019, 23:32
Re: GUI Slider to Send Keystroke to Application?
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?
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?
Re: GUI Slider to Send Keystroke to Application?
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.
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.
-
- Posts: 117
- Joined: 23 Aug 2019, 23:32
Re: GUI Slider to Send Keystroke to Application?
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:
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!
(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 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!
Re: GUI Slider to Send Keystroke to Application?
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
-
- Posts: 117
- Joined: 23 Aug 2019, 23:32
Re: GUI Slider to Send Keystroke to Application?
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
Re: GUI Slider to Send Keystroke to Application?
Problem solved!
-
- Posts: 117
- Joined: 23 Aug 2019, 23:32
Re: GUI Slider to Send Keystroke to Application?
Yes. I'm a little unsure how to incorporate the tempo slider with the playback and fast-forward buttons without everything going to pieces…?
Re: GUI Slider to Send Keystroke to Application?
Straightforward: add one line, control, or small section at a time. Retest iteratively along the way.
-
- Posts: 117
- Joined: 23 Aug 2019, 23:32
Re: GUI Slider to Send Keystroke to Application?
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
Re: GUI Slider to Send Keystroke to Application?
Follow the script line by line. Which line defines winTitle?
-
- Posts: 117
- Joined: 23 Aug 2019, 23:32
Re: GUI Slider to Send Keystroke to Application?
Thanks. I was able to get the slider to work by reinserting this at the top:
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:
…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?
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
Re: GUI Slider to Send Keystroke to Application?
You can post your latest revised script for more feedback about it.
-
- Posts: 117
- Joined: 23 Aug 2019, 23:32
Re: GUI Slider to Send Keystroke to Application?
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:
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
Re: GUI Slider to Send Keystroke to Application?
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
-
- Posts: 117
- Joined: 23 Aug 2019, 23:32
Re: GUI Slider to Send Keystroke to Application?
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
Re: GUI Slider to Send Keystroke to Application?
If you do not need the loop, you can replace it with Return.
-
- Posts: 117
- Joined: 23 Aug 2019, 23:32
Re: GUI Slider to Send Keystroke to Application?
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.)
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.)