-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSpaceCadetShift.ahk
48 lines (40 loc) · 1.89 KB
/
SpaceCadetShift.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
~RShift::
~LShift::
;Configuration
AcceptableMouseMovementPixels := 30 ;Normally around 30. Set to 10000 to disable mouse checking. Can be set very low because mouse should barely move while typing.
LongestAcceptableShiftTapTime := 1500 ;Normally around 1500. Set to 10000 to type bracket no matter how long shift is held
;Mouse clicks are ignored by A_PriorKey when shift is pressed
;Therefore an alternative method must be used to detect shift-click select as no "keys" are pressed
;This will be done by checking mouse position before and after {Shift Up} to see if something might be highlighted
;Tooltip %A_PriorKey%
MouseGetPos, startingXpos, startingYpos
KeyWait Shift
;Tooltip "Shift Released"
;Sleep 100
MouseGetPos, endingXpos, endingYpos
xPosChange := Abs(startingXpos - endingXpos)
yPosChange := Abs(startingYpos - endingYpos)
MousePosChangeOverall := xPosChange + yPosChange
;Tooltip %MousePosChangeOverall%
;Sleep 100
If ( A_TimeSincePriorHotkey < LongestAcceptableShiftTapTime and InStr(A_PriorKey,"Shift") and MousePosChangeOverall < AcceptableMouseMovementPixels )
SendRaw, % InStr(A_ThisHotkey,"LShift") ? "(" : ")"
Return
;Debugging section
ShiftWasLastKey := InStr(A_PriorKey,"Shift")
IsTapTimeAcceptable := A_TimeSincePriorHotkey < LongestAcceptableShiftTapTime
IsMouseMoveAcceptable := MousePosChangeOverall < AcceptableMouseMovementPixels
Tooltip,
(LTrim
"Taptime" %IsTapTimeAcceptable%
"Shiftpressed" %ShiftWasLastKey%
"Prior" %A_PriorKey% & %A_TimeSincePriorHotkey%
"Mouse" %IsMouseMoveAcceptable%
)
Sleep 1500
Tooltip
Return