Unable to utilize numpad as my keyboard trigger

Viewed 135

I am trying to change media using Autohotkey. I want to utilize Left Shift (<+) + LWin (<#) + Numpad8. Here is my code below but it does not work. I am having issues trying to utilize my Numpad8 to change music. I already know I can use the regular numbers on top of my keyboard but I would like to utilize my numpad instead. Please advise, thanks.

<+<#NumPad8::
Send {Media_Next}
return
1 Answers

From the Numpad Section of the docs, they mention:

If NumLock is OFF but Shift is pressed, the system temporarily releases Shift and acts as though NumLock is ON.

This appears to also be applicable vice versa, as holding Shift while Numlock is on before clicking NumPad8 instead appears to send NumpadUp instead of Shift+Numpad8.

We can work around this by creating a Hotkey to activate when Win+NumpadUp[+ any other modifier keys (such as Shift)] is pressed, and then check ourselves whether Shift and Numlock are active. If they are, then we Send the Media key.

Current Code:

*#NumPadUp::
if(GetKeyState("NumLock", "T") and GetKeyState("Shift", "P"))
    Send {Media_Next}
return

However, if we hold down Win+Shift while repeatedly pressing the key, it appears to revert back from NumpadUp to Numpad8. In order to account for this, we can reuse the body of the previous Hotkey in a new Hotkey that activates when *#NumPad8 is used.


Final Code:

*#NumPadUp::
*#NumPad8::
if(GetKeyState("NumLock", "T") and GetKeyState("Shift", "P"))
    Send {Media_Next}
return

Edit: Thank you @samthecodingman for bringing up an optimization that I missed- code has been edited to include this

Related