Use Numpad for AHK while Mousekeys is activated Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
hotkeyuser1234
Posts: 67
Joined: 07 Mar 2020, 12:27

Use Numpad for AHK while Mousekeys is activated

Post by hotkeyuser1234 » 24 Jan 2021, 11:32

Dear community,

I like using both AHK and mousekeys. It seems like keys on the numpad are not recognized while Mousekeys is activated as also discussed here: https://autohotkey.com/board/topic/101198-autohotkey-along-side-windows-mouse-keys/.

I would be happy if you could provide me support for one of two resolution ideas:
1) Is there a way to still get the Numpad keys working while Mousekeys is on so that I could e.g. use

Code: Select all

PgDn & NumPgDn
for AHK?
2) Are you aware of an AHK script that imitates the behavior of Mousekeys? I found a few scripts including https://github.com/DarthBrento/MouseKeysPlusPlus/blob/master/MouseKeys%2B%2B.ahk but it does not seem to work.

Thank you very much in advance for your answer!
User avatar
mikeyww
Posts: 5347
Joined: 09 Sep 2014, 18:38

Re: Use Numpad for AHK while Mousekeys is activated

Post by mikeyww » 24 Jan 2021, 11:45

Here is MouseKeys. You can now add whatever you like.

Code: Select all

amount   := 3
mouseKey := {1: [-1,  1], 2: [ 0,  1], 3: [ 1,  1], 4: [-1,  0], 6: [ 1,  0], 7: [-1, -1], 8: [ 0, -1], 9: [ 1, -1]}
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad6::
Numpad7::
Numpad8::
Numpad9::MouseMove, amount * mouseKey[key := SubStr(A_ThisHotkey, 7)].1, amount * mouseKey[key].2,, R
hotkeyuser1234
Posts: 67
Joined: 07 Mar 2020, 12:27

Re: Use Numpad for AHK while Mousekeys is activated

Post by hotkeyuser1234 » 24 Jan 2021, 12:07

Wow, this is awesome, thank you so much!

One thing which would make it even greater is acceleration over time like in the mousekeys program. A way how I could imagine it is e.g. pressing

Code: Select all

PgDn & NumPgDn 
to go down with usual speed and pressing NumPgDn twice (while holding PgDn) would double the speed. Is this possible somehow?

Thanks for your further help!
User avatar
mikeyww
Posts: 5347
Joined: 09 Sep 2014, 18:38

Re: Use Numpad for AHK while Mousekeys is activated  Topic is solved

Post by mikeyww » 24 Jan 2021, 13:05

Here is an adjustable accelerator.

Code: Select all

moveMin := 2, moveMax := 150, overSec := 5
F3::SoundBeep, (mouseKeysOn := !mouseKeysOn) ? 1500 : 1000, 30 ; F3 = Toggle MouseKeys
F4:: ; F4 = Exit
SoundBeep, 1000, 30
ExitApp

#If mouseKeysOn
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad6::
Numpad7::
Numpad8::
Numpad9::
start := A_TickCount
While GetKeyState(A_ThisHotkey, "P") { ; Accelerate while key is held
 amount := Min(moveMax, Round(moveMin + (A_TickCount - start) * (moveMax - moveMin) / overSec / 1000))
 move(SubStr(A_ThisHotkey, 7), amount)
}
Return

move(key, amount) {
 Static mouseKey := { 7: [-1, -1], 8: [ 0, -1], 9: [ 1, -1]
                    , 4: [-1,  0]             , 6: [ 1,  0]
                    , 1: [-1,  1], 2: [ 0,  1], 3: [ 1,  1]}
 MouseMove, amount * mouseKey[key].1, amount * mouseKey[key].2,, R
}
If you need to use something like PgDn as an auxiliary key, below is an example of how you can determine whether it is being held.

Code: Select all

PgDn::
Numpad4::
Numpad5::
num := GetKeyState("Numpad4", "P") || GetKeyState("Numpad5", "P")
aux := GetKeyState("PgDn", "P")
If num && aux
 Send Both `
Else Send %A_ThisHotkey% `
Return
This second way is trickier-- prone to getting stuck.
hotkeyuser1234
Posts: 67
Joined: 07 Mar 2020, 12:27

Re: Use Numpad for AHK while Mousekeys is activated

Post by hotkeyuser1234 » 24 Jan 2021, 14:02

Perfect, thank you! This is so nice:) I'll now only complement it with left, right and double left click
Post Reply

Return to “Ask For Help”