r/AutoHotkey • u/lindsay_wilson_88 • 20h ago
Meta / Discussion Shift + Numpad hotkeys - why is it so much agony?!?
A question and a rant ๐คฃ
The question: WHY does Windows behave the way it does regarding Shift and the Numpad? Why does it strip away/suppress/hide the shift modifier? If I have a keyboard with a numpad, I'm most likely also going to have a nice separate set of arrow keys and a bunch of home/end/pgup/pgdown keys. Why on earth would I want to press shift plus the numpad keys to get these actions?!?
Background: Recently learned about box-drawing characters (https://en.wikipedia.org/wiki/Box-drawing_characters) and figured it would be neat to write a script so I can easily enter them using the numpad keys (so 7 is a top-left corner, 9 is a top-right and so on). If you haven't seen the characters before, they are:
โ โญ โฌ โฎ โ โ โณ โ โ โฆ โ
โ โผ โค โฃ โ โซ โ โฌ โฃ
โ โฐ โด โฏ โ โ โป โ โ โฉ โ
โ โ โฑ โฒ โณ โ โ โ โ
โ โ โ โ
(assuming you're viewing this in a font which supports them)
I finally decided on using ctrl, shift, ctrl+shift and ctrl+alt modifier keys. And of course all hell broke loose when I came to handling the shift modifier, thanks to Windows' behavior of stripping the shift modifier away!
Like others have described, the solution was to handle both key names (e.g. NumpadHome and Numpad7) and then actually check the states of the NumLock and Shift keys using GetKeyState(). For example, here's what I have to handle the "7" key with both the ctrl and ctrl+shift modifiers:
<^$NumpadHome::
<^$Numpad7::
{
if GetKeyState("NumLock","T")
{
if GetKeyState("Shift","P")
{
Send "โ"
} else {
Send "โ"
}
} else {
Send "{LControl}{NumpadHome}"
}
}
I now have a functioning script which lets me enter all the characters I want, plus I did another script in v1 (for a WinXP machine). This threw up a few more weird quirks which I won't go in to but they took up some time to fix as well ๐คฃ
All of that faff when a simple <^$Numpad7:: Send"โ" would've worked if Windows treated shift + numpad like every other modifier!