GUI Slider to Send Keystroke to Application?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
mikeyww
Posts: 27286
Joined: 09 Sep 2014, 18:38

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 05 Feb 2022, 17:08

I doubt it would help. You could try something like this, which includes the window class but only inside the loop. At least it worked here.

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, Add, Slider, xm+40 ys+55 w250 Range0-10 Buddy1t1 Buddy2t2 TickInterval AltSubmit gAdjust vslide, 0
WinSet, Transparent, 200
Loop {
 WinWaitActive, ahk_class WindowsForms10.Window.8.app.0.2bf8098_r9_ad1 %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: 113
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 07 Feb 2022, 19:00

When I loaded it up, on this version in the window did not even appear. :-(

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

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 07 Feb 2022, 19:14

Hmm... Sorry you are having so much trouble. It's been working well here. It's possible that your program uses a different window class, I suppose. You can check with Window Spy. I'm not sure what else may be the trouble at your end, but you may be able to debug first by simply forcing the GUI to be displayed without that loop. You can then see whether the GUI itself works.

This version works here. If your slider does not work, I would see if you can alter the playback speed by pressing the MusicBee hotkey manually. If that works, then you can add a MsgBox to display the value of slide. If that value looks correct, then it should be working if the buttons also work.

Code: Select all

winTitle = ahk_exe MusicBee.exe
x := A_ScreenWidth - 725, y := 500
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, Add, Slider, xm+40 ys+55 w250 Range0-10 Buddy1t1 Buddy2t2 TickInterval AltSubmit gAdjust vslide, 0
WinSet, Transparent, 200
Gui, Show, x%x% y%y% h100 NoActivate, Playback speed
Return

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: 113
Joined: 23 Aug 2019, 23:32

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 07 Feb 2022, 22:05

Well, I'm grateful you've spent so much time thinking about this silly script. Everything in your most recent script works, (tempo slider and time skip buttons.) It's something about the hiding feature that makes the button stop working. But what you just posted works.

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

Re: GUI Slider to Send Keystroke to Application?

Post by mikeyww » 08 Feb 2022, 05:24

OK. At least it's something! Enjoy. :)

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

Re: GUI Slider to Send Keystroke to Application?

Post by SmithyZoomZoom » 09 Feb 2022, 21:56

Thanks for all your help. If I manage to get the final leg of the mystery untangled, I will post it here.

Post Reply

Return to “Ask for Help (v1)”