简体   繁体   中英

; 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 ...

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 

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.

#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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM