0
votes

Purpose: When doing formula's in a spreadsheet, I want to be able to add a parenthesis without taking my hand off of the keypad.

How can I remap NumLock with AutoHotKey to do the following:

  1. Single press = changes NumLock state (If ON, then OFF. If OFF, then ON.)
  2. Double press followed by NumpadDiv = Left Parenthesis
  3. Double press followed by NumpadMult = Right Parenthesis
  4. Double press, followed by nothing = nothing changes (timeout)

My code:


~NumLock::
if (A_PriorHotkey <> "~NumLock" or A_TimeSincePriorHotkey > 400)

{
    ; Too much time between presses, so this isn't a double-press.
    send {numlock}
    return
}

SetTimer, WatchKeys, 200

return


    WatchKeys:
        if GetKeyState("NumpadDiv") 
            SendInput, {(}
        else if GetKeyState("NumpadMult") 
            SendInput, {)}
        else
            SetTimer, WatchKeys, off
            SetNumlockState, on
        return

1

1 Answers

0
votes

I suggest using Numlock as a modifier key, that is like Shift, so you would press and hold Numlock then press / for an opening parenthesis. It might a few tries to get used to but then it feels natural (I'm using Numlock-based control of media player for a few years).

And the entire script would be:

NumLock & NumpadDiv::send (
NumLock & NumpadMult::send )