1

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 ...
Carucel
  • 435
  • 5
  • 11

3 Answers3

1

In my opinion, there are two possible ways to make point 2 work.

Method 1: keeps the Left Shift key's default behavior

shift + ; results in : colon key being pressed. You can get point 2 to work by adding tilde "~" key before `; and removing

else 
    send `;

With ~ you can keep the key's default behavior. The new script will look something like this

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

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

By using this method script will be able to send : with shift+;.

Method 2: removing the Left Shift key's default behavior

Add the following snippet in your code

LShift::
    Send, {} 
return 

This snippet will make the point 2 work but will render Left Shift key pretty much useless for everything else.

EDIT

Method 3: Making ; wait for x

Adding KeyWait into the script will make it wait a certain amount of time before executing the code. Secondly using Lshift + ; as an individual hotkey combination will output to :, removing the need for using ~ in return.

`;::
KeyWait, `;, T0.2
    Send `;
return

LShift & `;::
    Send `:
return 

`; & x::
KeyWait, `;, T0.2 
if GetKeyState("LShift", "P")
    ...
else
    ...
return 
akshif
  • 191
  • 1
  • 1
  • 10
  • Thank you, but using method 1 a keypress of `;` immediately produces `;`, instead of waiting for a `x` to act as a modifier key, and using method 2, making the left shift key completely useless for other key combinations is not really an option. – Carucel Apr 12 '20 at 18:38
  • Waiting is not really acceptable. Could you explain to me the assymetry between `;` and `:` in my original almost-solution. – Carucel Apr 13 '20 at 06:21
1

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.

Carucel
  • 435
  • 5
  • 11
1
#MaxThreadsPerHotkey 2 ; allow 2 "instances" of the hotkey subroutine to exist simultaneously

`;::
If (A_PriorKey = "`;") ; ; was pressed alone
    Send `;
return

LShift & `;:: Send :

`; & x::
if GetKeyState("LShift", "P") ;  ; & LShift & x
    Send a
else                          ; ; & x
   Send b
return
user3419297
  • 9,537
  • 2
  • 15
  • 24
  • Works for me.Could you test it with another keyboard? Some keyboards can't handle particular combinations of three keys, which is known as ["key jamming and ghosting"](https://en.wikipedia.org/wiki/Rollover_(key)). – user3419297 Apr 14 '20 at 14:58
  • Thank you for you explaination, but that is not the reason. I tested it with an external keyboard and had the same problem: if i first press and hold shift, and then press the `:` key, immediately a `:` will be typed. This is the original problem I had in my question. I can't explain why it doesn't happen to `;` without shift. – Carucel Apr 14 '20 at 16:20