-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathNull Movement.ahk
194 lines (156 loc) · 4.13 KB
/
Null Movement.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
; Null Movement Script for AutoHotkey v2
; This script updates the A and D keys so that only one is held down at a time
; This avoids the situation where game engines treat holding both strafe keys as not moving
; Instead, holding both strafe keys will cause you to move in the direction of the last one that was pressed
; The same logic is applied to the W and S keys (only one can be held at a time)
; Cheers to https://www.youtube.com/watch?v=Feny5bs2JCg&t=335s for mentioning this
; Changelog:
; 2024-08-10: simpler global usage with single global specifier
; 2024-07-26: Adding MaxThreads 1 and MaxThreadsBuffer 1
; 2024-07-26: Changing to use SendInput instead of Send, removing a couple if statements in key down events
; 2024-07-25: Adding section to allow for end button to close script, leaving commented for the moment
; 2024-07-25: Changed to use scancodes for multi-layout keyboard support
; 2024-07-25: Added requires v2 line
; Scan Code Mappings:
; W SC011
; A SC01E
; S SC01F
; D SC020
#Requires AutoHotkey v2
#SingleInstance force
#MaxThreads 1
#MaxThreadsBuffer 1
Persistent true
ListLines False
KeyHistory 0
ProcessSetPriority "High"
A_MaxHotkeysPerInterval := 99000000
A_HotkeyInterval := 0
global a_held := 0 ; Variable that stores the actual keyboard state of the A key
global d_held := 0 ; Variable that stores the actual keyboard state of the D key
global a_scrip := 0 ; Variable that stores the state of the A key output from the script
global d_scrip := 0 ; Variable that stores the state of the D key output from the script
global w_held := 0
global s_held := 0
global w_scrip := 0
global s_scrip := 0
/* Un-comment this section if you want the end button to open a dialog that asks to close the script
ToolTip "Script Enabled",A_ScreenWidth/2,A_ScreenHeight/2
SetTimer () => ToolTip(), -1000
End:: ; <--- this button exits the script
{
Result := MsgBox("Are you sure you want to exit?",, 4)
if Result = "Yes"
{
ExitApp
}
}
*/
*$SC01E:: ; *$a:: ; Every time the a key is pressed, * to include occurences with modifiers (shift, control, alt, etc)
{
global
a_held := 1 ; Track the actual state of the A key
if d_scrip
{
d_scrip := 0
SendInput "{Blind}{SC020 up}" ; Release the D key if it's held down, {Blind} so it includes any key modifiers (shift primarily)
}
a_scrip := 1
SendInput "{Blind}{SC01E down}" ; A down key
}
*$SC01E up:: ; *$a up:: ; Every time the a key is released
{
global
a_held := 0
if a_scrip
{
a_scrip := 0
SendInput "{Blind}{SC01E up}" ; A up key
}
if d_held && !d_scrip
{
d_scrip := 1
SendInput "{Blind}{SC020 down}" ; D down key if it's held
}
}
*$SC020:: ; *$d::
{
global
d_held := 1
if a_scrip
{
a_scrip := 0
SendInput "{Blind}{SC01E up}" ; Release the A key if it's held down
}
d_scrip := 1
SendInput "{Blind}{SC020 down}" ; D down key
}
*$SC020 up:: ; *$d up::
{
global
d_held := 0
if d_scrip
{
d_scrip := 0
SendInput "{Blind}{SC020 up}" ; D up key
}
if a_held && !a_scrip
{
a_scrip := 1
SendInput "{Blind}{SC01E down}" ; A down key if it's held
}
}
*$SC011:: ; *$w::
{
global
w_held := 1
if s_scrip
{
s_scrip := 0
SendInput "{Blind}{SC01F up}"
}
w_scrip := 1
SendInput "{Blind}{SC011 down}"
}
*$SC011 up:: ; *$w up::
{
global
w_held := 0
if w_scrip
{
w_scrip := 0
SendInput "{Blind}{SC011 up}"
}
if s_held && !s_scrip
{
s_scrip := 1
SendInput "{Blind}{SC01F down}"
}
}
*$SC01F:: ; *$s::
{
global
s_held := 1
if w_scrip
{
w_scrip := 0
SendInput "{Blind}{SC011 up}"
}
s_scrip := 1
SendInput "{Blind}{SC01F down}"
}
*$SC01F up:: ; *$s up::
{
global
s_held := 0
if s_scrip
{
s_scrip := 0
SendInput "{Blind}{SC01F up}"
}
if w_held && !w_scrip
{
w_scrip := 1
SendInput "{Blind}{SC011 down}"
}
}