Shift Key Training Wheels and Shift Parenthesis Remap

I want to use AutoHotKey to change the functionality of my toggle keys. The functionality is described in the Steve Losch blog post here . In particular, I would like my switch keys to do the following:

  • If LShift or RShift is pressed and released in less than 300 ms without pressing other keys, send ( or ) accordingly.
  • If LShift and RShift are combined together (press LShift , press RShift , release LShift , release RShift , etc.) in less than 300 ms, send () or )( .
  • If the shift key is used incorrectly ( LShift and S , RShift and K , etc.), then nothing happens.

I am having problems with the 300 ms requirement and the rolling functionality. In particular, I am having problems with the ability to detect when a key is released due to keyboard shortcuts, such as:

 LShift & 0:: return 

This is where I am now:

 LShift:: Send {LShift Down} KeyWait, LShift Send {LShift Up} if (A_TimeSinceThisHotkey < 300){ if (A_PriorKey = "LShift") { Send {)} } } return 
+4
source share
4 answers

I see no reason to use a 300 ms timeout anyway, it seems unreliable and unnecessary.
Take a look at this commented code, it is short and efficient, and seems to meet all your requirements:

 LShift::Send, ( RShift::Send, ) LShift & RShift:: Send, () RShift & LShift:: Send, )( /* Put your unwanted combinations here * and let them do nothing */ LShift & q::return RShift & y::return 

Edit:
Since LShift and RShift are already prefix hotkeys, I forgot the trick described here .

+2
source

I felt compelled to understand this. Here you go!

Basically, I created a hotkey for each Shift + Letter key combination to send the correct key case and also set the value to Abort . The Abort value is then referenced when one of the Shift keys is pressed to determine whether or not to send the corresponding ones.

Rolling was accomplished by creating a Hotkey for LShift + RShift (and vice versa). He then looks at which key is issued first to determine () or )( .

Accept if this is what you were looking for!

 Loop 26 { Hotkey, % "~LShift & " Chr(A_Index+96), LetterKey ; Hotkeys for AZ Hotkey, % "~RShift & " Chr(A_Index+96), LetterKey ; Hotkeys for AZ } Return RShift:: LShift:: Abort := 0 keyDown := A_TickCount Keywait, % A_ThisHotkey duration := A_TickCount - keyDown If (duration < 200) and (Abort = 0) SendInput % (A_ThisHotkey = "LShift") ? "(" : ")" Send {LShift Up} Return RShift & LShift:: LShift & RShift:: Keywait, LShift If GetKeyState("RShift", "P") { Keywait, RShift Send () } Else Send )( Return LetterKey: SendInput, % "+" SubStr(A_ThisHotKey, 0, 1) Abort := 1 Return 

EDIT: Hmm, I seem to have the same problem as you. I always get a duration of 0 due to keyboard shortcuts.

0
source

MCL's answer is close, but when I tested it, I found that clicking on the click did not select the text. Here is the version with firmware that allows you to click the mouse to work.

 ;shift to parens LShift::Send, ( RShift::Send, ) LShift & RShift:: Send, () RShift & LShift:: Send, )( ;passthrough for shift-click LShift & LButton:: Send, {LShift Down}{LButton} Send, {LShift Up} RShift & LButton:: Send, {RShift Down}{LButton} Send, {RShift Up} 

I do not think that a 300 ms timeout is possible without a deep understanding of the implementation of autohotkey or the actual modification for autohotkey. When I tried to get it to work (using http://www.autohotkey.com/board/topic/98742-remapping-shift-key/ ), I found that A_PriorHotkey not constantly populated. I do not think that this variable is designed to work with modifier keys.

0
source

I found and modified this script in the AutoHotKey forums. (The original script was prone to type "K" ("when you intended to type" K "if you type too quickly, so I changed it to no longer exist)

 $LShift Up::send, % getkeystate("LShift") ? "{LShift Up}" : "" $RShift Up::send, % getkeystate("RShift") ? "{RShift Up}" : "" ~$LShift:: KeyWait, LShift, T0.1 ; wait 100ms to check shift state if (A_PriorKey = "LShift") { send, % getkeystate("LShift") ? "{LShift Down}" : "(" } KeyWait, LShift return ~$RShift:: KeyWait, RShift, T0.1 ; wait 100ms to check shift state if (A_PriorKey = "RShift") { send, % getkeystate("RShift") ? "{RShift Down}" : ")" } KeyWait, RShift return 
0
source

Source: https://habr.com/ru/post/1491347/


All Articles