-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspace_modifier.ahk
executable file
·159 lines (145 loc) · 4.03 KB
/
space_modifier.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: cy18 <thecy18@gmail.com>
;
; An improved script to use space as modifier
; In normal cases, if space is pressed for more than 0.1 second, it becomes a modifier, this time could be modified in the script
; If no other keys are pressed during space is pressed, a space is output when space is released
; Severial tunes are made so that the script works well when typing in fast speed
; Note that repeating space no longer works
#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.
StringCaseSense, On
AnyKeyPressedOtherThanSpace(mode = "P") {
keys = 1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./
Loop, Parse, keys
{
isDown := GetKeyState(A_LoopField, mode)
if(isDown)
return True
}
return False
}
supressed := False
RestoreInput(){
BlockInput, Off
Global supressed
supressed := False
}
SupressInput(){
Global supressed
supressed := True
BlockInput, On
SetTimer, RestoreInput, -180
}
ModifierStates := ""
UpdateModifierStates(){
Global ModifierStates
if (supressed){
return
}
ModifierStates := ""
if GetKeyState("LWin", "P") || GetKeyState("RWin", "P") {
ModifierStates .= "#"
}
if GetKeyState("Ctrl", "P"){
ModifierStates .= "^"
}
if GetKeyState("Alt", "P"){
ModifierStates .= "!"
}
if GetKeyState("Shift", "P"){
ModifierStates .= "+"
}
}
SendKey(Key, num=1){
Global ModifierStates
Loop, %num%{
Send, %ModifierStates%%Key%
}
}
ReleaseModifier(){
global space_up
if (not space_up){
space_up := true
}
Send, {RShift}
}
Space Up::
Send {Blind}{Space up}
space_up := true
SendEvent, {RShift}
return
Space::
if AnyKeyPressedOtherThanSpace(){
SendInput, {Blind}{Space}
Return
}
if (GetKeyState(LShift, mode)){
SendInput ^{Space}
Return
}
inputed := False
space_up := False
input, UserInput, L1 T0.05, {RShift}
if (space_up) {
Send, {Blind}{Space}
return
}else if (StrLen(UserInput) == 1){
Send, {Space}%UserInput%
return
}
SetTimer, ReleaseModifier, -18000
while true{
input, UserInput, L1, {RShift}
if (space_up) {
if (!inputed){
Send, {Blind}{Space}
}
break
}else{
inputed := True
StringLower, UserInput, UserInput
UpdateModifierStates()
SupressInput()
if (UserInput == "e")
SendKey("{Up}")
else if (UserInput == "d")
SendKey("{Down}")
else if (UserInput == "s")
SendKey("{Left}")
else if (UserInput == "a")
SendKey("{Left}", 8)
else if (UserInput == "f")
SendKey("{Right}")
else if (UserInput == "g")
SendKey("{Right}", 8)
else if (UserInput == "w")
SendKey("{Home}")
else if (UserInput == "r")
SendKey("{End}")
else if (UserInput == "c")
SendKey("{BS}")
else if (UserInput == "x")
SendKey("{BS}", 6)
else if (UserInput == "v")
SendKey("{DEL}")
else if (UserInput == "b")
SendKey("{DEL}", 6)
else if (UserInput == "5")
SendKey("{F5}")
else if (UserInput == "8"){
RestoreInput()
break
}else if (UserInput == "`t")
SendKey(" ")
else
Send, {Blind}%UserInput%
}
}
RestoreInput()
return