-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumpad.lua
70 lines (56 loc) · 1.68 KB
/
numpad.lua
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
local numpadLayerActive = false
-- Function to enable or disable the numpad layer
function toggleNumpadLayer()
numpadLayerActive = not numpadLayerActive
end
-- Listen for Control + F20 to toggle the numpad layer
hs.hotkey.bind({"ctrl"}, "F20", toggleNumpadLayer)
-- Define the numpad key mappings based on the specified layout
local numpadMappings = {
b = "1",
n = "2",
m = "3",
h = "4",
j = "5",
k = "6",
y = "7",
u = "8",
i = "9",
["7"] = "/",
["8"] = "*",
["9"] = "-",
l = "return",
o = "return",
[","] = ".",
space = "0"
}
-- Eventtap to remap keys when the numpad layer is active
local numpadEvent = hs.eventtap.new({hs.eventtap.event.types.keyDown}, function(event)
if numpadLayerActive then
local keyCode = event:getKeyCode()
local character = hs.keycodes.map[keyCode]
if numpadMappings[character] then
hs.eventtap.keyStrokes(numpadMappings[character])
return true
end
end
return false
end)
-- Eventtap to remap keys when the numpad layer is active
local numpadEvent = hs.eventtap.new({hs.eventtap.event.types.keyDown}, function(event)
if numpadLayerActive then
local keyCode = event:getKeyCode()
local character = hs.keycodes.map[keyCode]
if numpadMappings[character] then
local output = numpadMappings[character]
if output == "return" or output == "padclear" then
hs.eventtap.keyStroke({}, output, 0)
else
hs.eventtap.keyStrokes(output)
end
return true
end
end
return false
end)
numpadEvent:start()