autohotkeymodifier-key

; as a new modifier key


I want ; to be a new modifier key. The following works almost perfectly.

`;::
if GetKeyState("LShift", "P")
    Send `:
else
    Send `;
return

`; & x::
if GetKeyState("LShift", "P")
    ...
else
    ...
return

Only point 2. of the following wishlist does not work. Does anybody know how to fix this code?

  1. ; to be ; when pressed alone
  2. shift ; to be : when pressed alone
  3. ; with x to be the second ...
  4. shift with ; with x to be the first ...

Solution

  • The following works perfectly, but is ugly code due to code duplication. Maybe cleaner code is possible.

    started := 0
    LShift & `;::
    if started = 0
        started := A_TickCount
    return
    `;::
    if started = 0
        started := A_TickCount
    return
    
    LShift & `; Up::
    if A_TickCount - started < 500
        Send `:
    started = 0
    return
    
    `; Up::
    if A_TickCount - started < 500
        Send `;
    started = 0
    return
    
    `; & x::
    started = 0 ; <==== !
    if GetKeyState("LShift", "P")
        ...
    else
        ...
    return
    

    The key ; now works as modifier key whenever it is used in a combination with x (without delay) or if it is pressed more than half a second. The delay is not neccesary and can be removed; it's just there prevent misinterpretation of an accidental modifier keypress as a ;. The colon : works correctly too.