0
votes

Using AutoHotKey, I want to send through a hotkey (^l) the forward slash key viz. {/} continuously after a gap of 10 seconds (Sleep,10000) to Media Player Application only if it is the active window. If any other window is the active window, then the forward slash should not be sent.

The hotkey (^l) key should be a toggle, ie pressing it again should stop sending the forward slash key.

(ahk_class of Media Player Classic:) ahk_class MediaPlayerClassicW

Thanks in advance for the pointers/help.

1

1 Answers

1
votes
#IfWinActive ahk_class MediaPlayerClassicW ; only if it is the active window

    ^l::
       send_key := !send_key ; toggles the variable "send_key" between true and false
       if (send_key)  ; is true
            SetTimer send_the_key, 10000
        else
            SetTimer send_the_key, Off
    return

    send_the_key:
        If WinActive("ahk_class MediaPlayerClassicW")
            send /
        else   ; if you want to stop the timer whenever the window gets inactive
        {
            SetTimer send_the_key, Off
            send_key := false
        }
    return

#IfWinActive ; turn off context sensitivity

https://www.autohotkey.com/docs/commands/_IfWinActive.htm

https://www.autohotkey.com/docs/commands/SetTimer.htm