Issue with AHK Script - Numpad1 and NumpadDel Conflict

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CrowexBR
Posts: 4
Joined: 15 Apr 2024, 06:57

Issue with AHK Script - Numpad1 and NumpadDel Conflict

15 Apr 2024, 07:11

Hello everyone,

I've encountered an issue with my AHK script that I hope someone can help me troubleshoot. I've set up multiple hotkeys using numpad[1-9] and numpadDel to execute various actions simultaneously. However, I've noticed a bug where sometimes the script behaves unexpectedly.

For example, when I press numpad1 + numpadDel, it automatically triggers the action, but then after a few seconds, it triggers again without me pressing numpadDel. Additionally, I have a functionality in my script where pressing numpad1 should open the chat to input numbers, but sometimes even without pressing numpadDel, it still triggers the action as if I did.

To temporarily resolve this issue, I've found that pressing numpadDel again stops the unintended behavior. However, it's disrupting my workflow, and I'd like to find a permanent solution.

Has anyone encountered a similar issue with AHK scripts before? If so, could you please share how you resolved it or any suggestions for troubleshooting?
gregster
Posts: 9037
Joined: 30 Sep 2013, 06:48

Re: Issue with AHK Script - Numpad1 and NumpadDel Conflict

15 Apr 2024, 07:28

If you have a problem with your script, I can only recommend to post it (between code tags please).

Generally, your problem description could possibly hint at a missing return at the end of a multi-line hotkey so that code execution falls through to following code. But this is just guesswork without seeing the code. The KeyHistory might help to analyse the situation.
RussF
Posts: 1270
Joined: 05 Aug 2021, 06:36

Re: Issue with AHK Script - Numpad1 and NumpadDel Conflict

15 Apr 2024, 07:53

It is logically impossible to press Numpad1 and NumpadDel at the same time.

If your NumLock is turned ON, pressing the 1/End key on your numpad will be recognized by AHK as Numpad1, however, pressing the ./Del key on your numpad will be seen as NumpadDot.

Conversely, with NumLock OFF, 1/End will be seen as NumpadEnd and ./Del will be seen as NumpadDel

Determine whether you will have NumLock ON or OFF for your script and program accordingly - or program to take both possibilities into account.

Russ
gregster
Posts: 9037
Joined: 30 Sep 2013, 06:48

Re: Issue with AHK Script - Numpad1 and NumpadDel Conflict

15 Apr 2024, 08:03

RussF wrote:
15 Apr 2024, 07:53
It is logically impossible to press Numpad1 and NumpadDel at the same time.
It works here :) , although it's not a nice key combo...

This code triggers when I press Numpad1 (keeping it pressed down) and then Shift and Numpad , (german layout has a Numpad comma instead of the dot, but it's still NumpadDot as far as AHK is concerned) - as long as NumLock is ON:

Code: Select all

Numpad1 & NumpadDel::msgbox
https://www.autohotkey.com/docs/v1/KeyList.htm#numpad wrote:If NumLock is OFF but Shift is pressed, the system temporarily releases Shift and acts as though NumLock is ON.
And vice versa, afaics: If NumLock is ON but Shift is pressed, the system acts temporarily as though NumLock is OFF.

edited
RussF
Posts: 1270
Joined: 05 Aug 2021, 06:36

Re: Issue with AHK Script - Numpad1 and NumpadDel Conflict

15 Apr 2024, 09:10

@gregster, I noticed some odd behavior with the Shift key as I was testing before responding to the OP's posting. Using the following script and testing within a block of text in Notepad:

Code: Select all

numpad1::msgbox % "Numpad 1"
numpadend::msgbox % "Numpad End"
numpaddot::msgbox % "Numpad Dot"
numpaddel::msgbox % "Numpad Del"
With Numlock ON, AHK triggered all the expected MsgBox's:
1/End : triggered "Numpad 1" message box
Shift-1/End : "Numpad End" message box
./Del : "Numpad Dot" message box
Shift-./Del : "Numpad Del" message box

However, with Numlock OFF,
1/End : "Numpad End" message box
Shift-1/End : No message box - highlights text from cursor to end of line as if pressing Shift-End
./Del : "Numpad Del" message box
Shift-./Del No message box - deletes one character in front of cursor

Therefore, if the docs are correct:
If NumLock is OFF but Shift is pressed, the system temporarily releases Shift and acts as though NumLock is ON.
with Numlock OFF, you would expect Shift-1/End to trigger the "Numpad 1" message box and Shift-./Del to trigger the "Numpad Dot" message box. No message boxes are triggered, however. Perhaps I am misunderstanding the docs?

Russ
gregster
Posts: 9037
Joined: 30 Sep 2013, 06:48

Re: Issue with AHK Script - Numpad1 and NumpadDel Conflict

15 Apr 2024, 10:28

@RussF:
Yeah, that sentence looks wrong and has confused me before, I think. NumLock has always been tricky - and the docs quite meager. I just remember from the past that when NumLock is OFF, you need these shifted hotkeys:

Code: Select all

+numpadend::msgbox % "Shifted Numpad End"
+numpaddel::msgbox % "Shifted Numpad Del"
I guess this makes sense since this actually corresponds to "normal" Numlock OFF behaviour: If you try without any AHK script running, a shifted NumpadEnd doesn't actually return a 1, and a shifted NumpadDown doesn't return a 2, but acts as a shifted Down key.

For Numlock ON, Shift seems to switch the Numlock state, though, to OFF. This should be mentioned in the docs... If NumLock is ON but Shift is pressed, the system temporarily releases Shift and acts as though NumLock is OFF.

So afaics, normal Windows behaviour with Shift already differs for the different Numpad states, ON and OFF, and the required AHK hotkey definitions mirror this (while the current sentence in the docs seem to contradict the whole thing).
In the past, I often deduced which numpad hotkeys I needed by trial-and-error :shh: . The docs should probably be clarified or corrected - but I think this is how the Windows Numpad and AHK always worked. Perhaps I miss something; I will have to take another look later. But this part should be clarified anyway, imo.
RussF
Posts: 1270
Joined: 05 Aug 2021, 06:36

Re: Issue with AHK Script - Numpad1 and NumpadDel Conflict

15 Apr 2024, 11:41

I just tested the above code in V2 and got the same results, so it hasn't been changed there and the V2 docs say the same thing. I will post a message in the wish list->documentation forum and tag this message to see if we can get some clarification.

Back to the original topic, however, I think (without seeing the OP's code) my original assessment of their problem would probably stand.

Russ
gregster
Posts: 9037
Joined: 30 Sep 2013, 06:48

Re: Issue with AHK Script - Numpad1 and NumpadDel Conflict

15 Apr 2024, 12:19

RussF wrote:
15 Apr 2024, 11:41
Back to the original topic, however, I think (without seeing the OP's code) my original assessment of their problem would probably stand.
Didn't Numpad1 & NumpadDel::msgbox with NumLock ON work for you like I described? In that direction, this is also the original Windows behaviour outside of AHK, afaics.
A shifted NumpadDot turns into NumpadDel... this is also what happens on my computer's Numpad when I run no AHK script at all.

But I guess what actually happens for the OP is speculation at this point, without seeing their code. Perhaps they actually use Numpad1 & NumpadDot::...
RussF
Posts: 1270
Joined: 05 Aug 2021, 06:36

Re: Issue with AHK Script - Numpad1 and NumpadDel Conflict

15 Apr 2024, 13:28

gregster wrote:A shifted NumpadDot turns into NumpadDel...
With no AHK, REGARDLESS of the state of Numlock, pressing Shift-./Del, you will get the Del function (at least on my PC). You never get the dot by pressing the Shift key in either Numlock state.

With Numlock ON, Shift-1/End gives you End (cursor is just moved to end of line). With Numlock OFF, Shift-1/End gives you Shift-End (characters are highlighted from cursor to end of line). Again, you never get the 1 key.

In fact, after further testing, it seems that shifting ANY of numpad keys with Numlock off does NOT get you the numbers - only shifted versions of the directional keys. However, with Numlock ON, shifted numpad keys get you the directional keys. Very counterintuitive. In retrospect, I guess it sort of makes sense. If you don't have a keyboard with the separate directional key section, you would need to make use of shifted directional keys on the numpad.

I've been using PCs since the original IBM came out in 1981 and I honestly never noticed this behavior. That said, I have always had a keyboard with three sections - main characters, cursor control keys and numeric keypad. I have always had Numlock turned on and I guess have never had to use the shifted versions of numpad keys and I just assumed that shifting those keys would get you the opposite of the current numlock state.

The docs, in my opinion, are still ambiguous, however.
If NumLock is OFF but Shift is pressed, the system temporarily releases Shift and acts as though NumLock is ON.
would lead you to believe that if Shift releases, and it behaves as thought Numlock were on, you would always get the number keys - which is what WOULD happen if Numlock were on and Shift wasn't pressed. That is not what happens. I'm so confused... :crazy:

Russ
CrowexBR
Posts: 4
Joined: 15 Apr 2024, 06:57

Re: Issue with AHK Script - Numpad1 and NumpadDel Conflict

19 Apr 2024, 15:28

Hey coders,

I found the solution:

Code: Select all

if GetKeyState("NumpadDot", "P")
:bravo:

With
GetKeyState
resolved everything what I need this.

Thanks for you all. :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Orecalque1915, Tio_oddish and 428 guests