-
Notifications
You must be signed in to change notification settings - Fork 0
/
halfqwerty
206 lines (178 loc) · 5.45 KB
/
halfqwerty
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
195
196
197
198
199
200
201
202
203
204
205
206
#SingleInstance, force
; Half-QWERTY: One-handed Typing - version 3a
; http://www.autohotkey.com/forum/viewtopic.php?p=228783#228783
;
; HalfKeyboard invented by Matias Corporation between 1992 and 1996
; Originally coded in AutoHotkey by jonny in 2004
; Many thanks to Chris for helping him out with this script.
; Capslock hacks and `~ remap to '" by Watcher
; This implementation was done by mbirth in 2007
;
; version 3a script, mod by hugov:
; 2008-10-31:
; - mixed with "Capitalize letters after 1 second hold" at request of Calibran
; http://www.autohotkey.com/forum/post-228311.html#228311
; just tested very briefly so try at your own peril :-)
;
; 2011-02-21
; - Added URLDownloadToFile for missing icon and keyboard layout
; images downloaded from www.autohotkey.net if not found in %A_ScriptDir%
; - Added menu option to show keyboard layout in an AlwaysOnTop Gui (via Tray)
; 2011-02-21
KeyIsDown = 0
UpperDelay = 1000
UpperDelay *= -1
IfExist, %A_ScriptDir%\halfkeyboard.ico ; mod 2011-02-21
{
Menu Tray, Icon, %A_ScriptDir%\HalfKeyboard.ico
Menu Tray, Tip, HalfKeyboard emulator
Menu Tray, Add, &Show Keyboard layout, MenuShowKeyboardLayout
Menu Tray, Add, E&xit, MenuExit
Menu Tray, NoStandard
}
RegRead KLang, HKEY_CURRENT_USER, Keyboard Layout\Preload, 1
StringRight KLang, KLang, 4
If (!KLang)
KLang := A_Language
If (KLang = "0407") {
; 0407 DE_de QWERTZ mirror set
original := "^12345qwertasdfgyxcvb"
mirrored := "ß09876poiuzölkjh-.,mn"
} Else If (KLang = "040c" || KLang = "040C") {
; 040c FR_fr AZERTY mirror set
original := "²&é" . """" . "'(azertqsdfgwxcvb" ; split up string for better
mirrored := ")àç" . "_" . "è-poiuymlkjh!:;,n" ; human readability
} Else {
; 0409 US_us QWERTY mirror set
;original := "``" . "12345qwertasdfgzxcvb" ; split up string for better
original := "``" . "12345',.pyaoeiudzqjk" ; split up string for better
;mirrored := "'" . "09876poiuy;lkjh/.,mn" ; human readability
mirrored := "'" . "09876lrcgfsnthdzvwmb" ; human readability
}
; Now define all hotkeys
Loop % StrLen(original)
{
c1 := SubStr(original, A_Index, 1)
c2 := SubStr(mirrored, A_Index, 1)
Hotkey Space & %c1%, DoHotkey
Hotkey Space & %c2%, DoHotkey
Hotkey %c1%, KeyDown
Hotkey %c1% UP, KeyUP
Hotkey %c2%, KeyDown ; see post by guest below seems to improve the script haven't tried this myself so comment these two lines if it doesn't work
Hotkey %c2% UP, KeyUP ;
}
return
; This key may help, as the space-on-up may get annoying, especially if you type fast.
Control & Space::Suspend
; Not exactly mirror but as close as we can get, Capslock enter, Tab backspace.
Space & CapsLock::Send {Enter}
Space & Tab::Send {Backspace}
; If spacebar didn't modify anything, send a real space keystroke upon release.
+Space::Send {Space}
Space::Send {Space}
; Define special key combos here (took them from RG's mod):
^1::Send {Home}
^2::Send {End}
^3::Send {Del}
; General purpose
DoHotkey:
StartTime := A_TickCount
StringRight ThisKey, A_ThisHotkey, 1
i1 := InStr(original, ThisKey)
i2 := InStr(mirrored, ThisKey)
If (i1+i2 = 0) {
MirrorKey := ThisKey
} Else If (i1 > 0) {
MirrorKey := SubStr(mirrored, i1, 1)
} Else {
MirrorKey := SubStr(original, i2, 1)
}
Modifiers := ""
If (GetKeyState("LWin") || GetKeyState("RWin")) {
Modifiers .= "#"
}
If (GetKeyState("Control")) {
Modifiers .= "^"
}
If (GetKeyState("Alt")) {
Modifiers .= "!"
}
If (GetKeyState("Shift") + GetKeyState("CapsLock", "T") = 1) {
; only add if Shift is held OR CapsLock is on (XOR) (both held down would result in value of 2)
Modifiers .= "+"
}
/*
KeyWait, %ThisKey%, T1
Send %Modifiers%{%MirrorKey%}
If (A_TickCount - StartTime >= 1000)
{
StringUpper, MirrorKey, MirrorKey
Send {Backspace}+%MirrorKey%
*/
If (KeyIsDown < 1 or ThisKey <> LastKey)
{
KeyIsDown := True
LastKey := ThisKey
Send %Modifiers%{%MirrorKey%}
SetKeyDelay, 65535
SetTimer, ReplaceWithUpperMirror, %UpperDelay%
}
Return
Space & F1::
; Help-screen using SplashImage
CoordMode Caret, Screen
y := A_CaretY + 20
If (y > A_ScreenHeight-100)
y := A_CaretY - 20 - 100
IfExist, %A_ScriptDir%\HalfKeyboard_help.gif ; 2011-02-21 for safety
{
SplashImage %A_ScriptDir%\HalfKeyboard_help.gif, B X%A_CaretX% Y%y%
Sleep 5000
SplashImage Off
}
return
MenuShowKeyboardLayout: ; 2011-02-21
IfWinNotExist, HalfKeyboard - permanent keyboard layout
{
Gui, +Owner +Toolwindow +AlwaysOnTop
Gui, Add, picture, x0 y0 w620 h208, %A_ScriptDir%\halfkeyboard_help.png
Gui, Show, w620 h208 NA, HalfKeyboard - permanent keyboard layout
Menu, Tray, Check, &Show Keyboard layout
}
Else
{
Gosub, GuiClose
}
Return
GuiClose:
Menu, Tray, UnCheck, &Show Keyboard layout
Gui, Destroy
Return
MenuExit:
ExitApp
Return
KeyDown:
Key:=A_ThisHotkey
If (KeyIsDown < 1 or Key <> LastKey)
{
KeyIsDown := True
LastKey := Key
Send %Key%
SetKeyDelay, 65535
SetTimer, ReplaceWithUpper, %UpperDelay%
}
Return
KeyUp:
Key:=A_ThisHotkey
SetTimer, ReplaceWithUpper, Off
SetTimer, ReplaceWithUpperMirror, Off
KeyIsDown := False
Return
ReplaceWithUpper:
SetKeyDelay, -1
Send {Backspace}+%LastKey%
Return
ReplaceWithUpperMirror:
SetKeyDelay, -1
Send {Backspace}+%MirrorKey%
Return