-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKeebMangler.ahk
190 lines (147 loc) · 4.18 KB
/
KeebMangler.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
; KeebMangler
; Copyright (C) 2021 Patrick McFarland <pmcfarland@adterrasperaspera.com>
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see http://www.gnu.org/licenses/.
#NoEnv
#Warn
#SingleInstance force
#UseHook on
Sendmode Input
SetWorkingDir %A_ScriptDir%
global version := "1.3"
global ini_km := "keebmangler"
global ini_clh := "capslock_hyper"
global ini_raa := "ralt_altgr"
global ini_mac := "mac_swap"
global ini_xev := "xev"
global menu_km := "KeebMangler"
global menu_clh := "CapsLock " . Chr(129046) . " Hyper"
global menu_raa := "RAlt " . Chr(129046) . " AltGr"
global menu_mac := "Mac Swap"
global menu_xev := "Event Spy (xev)"
global enable_clh
global enable_raa
global enable_mac
global enable_xev
global config := A_AppData . "/" . ini_km . ".ini"
; Load init
if (!FileExist(config)) {
FileAppend, "[%ini_km%]", %config%, CP0
}
IniRead, enable_clh, %config%, %ini_km%, %ini_clh%, %true%
IniRead, enable_raa, %config%, %ini_km%, %ini_raa%, %true%
IniRead, enable_mac, %config%, %ini_km%, %ini_mac%, %false%
IniRead, enable_xev, %config%, %ini_km%, %ini_xev%, %false%
; Menu
Menu, Tray, NoStandard
Menu, Tray, Icon, Shell32.dll, 174
Menu, Tray, Tip, %menu_km% %version% (AHK %A_AhkVersion%)
Menu, Tray, Add, %menu_clh%, handle_clh
Menu, Tray, Add, %menu_raa%, handle_raa
Menu, Tray, Add, %menu_mac%, handle_mac
Menu, Tray, Add,
Menu, Tray, Add, %menu_xev%, handle_xev
Menu, Tray, Add,
Menu, Tray, Add, Reload, handle_reload
Menu, Tray, Add, Exit, handle_exit
if(enable_clh)
Menu, Tray, ToggleCheck, %menu_clh%
if(enable_raa)
Menu, Tray, ToggleCheck, %menu_raa%
if(enable_mac)
Menu, Tray, ToggleCheck, %menu_mac%
if(enable_xev) {
Menu, Tray, ToggleCheck, %menu_xev%
SetTimer, Xev_Tooltip, 17
}
handle_clh() {
enable_clh := !enable_clh
Menu, Tray, ToggleCheck, %menu_clh%
IniWrite, %enable_clh%, %config%, %ini_km%, %ini_clh%
if(enable_clh)
SetCapsLockState AlwaysOff
else
SetCapsLockState Off
}
handle_raa() {
enable_raa := !enable_raa
Menu, Tray, ToggleCheck, %menu_raa%
IniWrite, %enable_raa%, %config%, %ini_km%, %ini_raa%
}
handle_mac() {
enable_mac := !enable_mac
Menu, Tray, ToggleCheck, %menu_mac%
IniWrite, %enable_mac%, %config%, %ini_km%, %ini_mac%
}
handle_xev() {
enable_xev := !enable_xev
Menu, Tray, ToggleCheck, %menu_xev%
IniWrite, %enable_xev%, %config%, %ini_km%, %ini_xev%
if(enable_xev)
SetTimer, Xev_Tooltip, 17
else
SetTimer, Xev_Tooltip, Off
}
handle_reload() {
Reload
}
handle_exit() {
ExitApp
}
; Xev
Xev_Tooltip() {
MouseGetPos, , , id, control
WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
ControlGetFocus, ActiveWin, A
pkeys := ""
lkeys := ""
Loop, 255 {
key := GetKeyName(Format("vk{:x}", A_Index))
if(key == "Shift" || key == "Alt" || key == "Control")
continue
if(GetKeyState(key, "p"))
pkeys = %pkeys% %key%
if(GetKeyState(key, ""))
lkeys = %lkeys% %key%
}
if(pkeys or lkeys)
Tooltip, physical: %pkeys%`nlogical: %lkeys%
else
Tooltip
}
; Maps
#if enable_clh
*CapsLock::send {Blind}{LCtrl down}{LAlt down}{LShift down}{LWin down}
*CapsLock Up::send {Blind}{LCtrl up}{LAlt up}{LShift up}{LWin up}
#if
#if enable_mac
*LAlt::send {Blind}{LWin down}
*LAlt up::send {Blind}{LWin up}
*LWin::send {Blind}{LAlt down}
*LWin up::send {Blind}{LAlt up}
*RAlt::send {Blind}{AppsKey down}
*RAlt up::send {Blind}{AppsKey up}
#if
#if !enable_mac && enable_raa
*RAlt::send {Blind}{LCtrl down}{RAlt down}
*RAlt up::send {Blind}{LCtrl up}{RAlt up}
#if
#if enable_mac && !enable_raa
*RWin::send {Blind}{RAlt down}
*RWin up::send {Blind}{RAlt up}
#if
#if enable_mac && enable_raa
*RWin::send {Blind}{LCtrl down}{RAlt down}
*RWin up::send {Blind}{LCtrl up}{RAlt up}
#if