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
| -- Boolean to track if mappings are enabled:
local mappingsEnabled = false
-- Function to bind `hjkl` to arrow keys with Control as a modifier
function mapControlToArrows()
local controlModifier = {"ctrl"}
local controlShiftModifier = {"ctrl", "shift"}
local repeatDelay = 0.1
local repeatInterval = 0.05
-- Bind Control + h to left arrow
hs.hotkey.bind(controlModifier, "h", function()
hs.eventtap.keyStroke({}, "left")
end, nil, function()
hs.eventtap.keyStroke({}, "left")
end)
-- Bind Control + j to down arrow
hs.hotkey.bind(controlModifier, "j", function()
hs.eventtap.keyStroke({}, "down")
end, nil, function()
hs.eventtap.keyStroke({}, "down")
end)
-- Bind Control + k to up arrow
hs.hotkey.bind(controlModifier, "k", function()
hs.eventtap.keyStroke({}, "up")
end, nil, function()
hs.eventtap.keyStroke({}, "up")
end)
-- Bind Control + l to right arrow
hs.hotkey.bind(controlModifier, "l", function()
hs.eventtap.keyStroke({}, "right")
end, nil, function()
hs.eventtap.keyStroke({}, "right")
end)
-- Bind Control + Shift + h to Shift + left arrow
hs.hotkey.bind(controlShiftModifier, "h", function()
hs.eventtap.keyStroke({"shift"}, "left")
end, nil, function()
hs.eventtap.keyStroke({"shift"}, "left")
end)
-- Bind Control + Shift + j to Shift + down arrow
hs.hotkey.bind(controlShiftModifier, "j", function()
hs.eventtap.keyStroke({"shift"}, "down")
end, nil, function()
hs.eventtap.keyStroke({"shift"}, "down")
end)
-- Bind Control + Shift + k to Shift + up arrow
hs.hotkey.bind(controlShiftModifier, "k", function()
hs.eventtap.keyStroke({"shift"}, "up")
end, nil, function()
hs.eventtap.keyStroke({"shift"}, "up")
end)
-- Bind Control + Shift + l to Shift + right arrow
hs.hotkey.bind(controlShiftModifier, "l", function()
hs.eventtap.keyStroke({"shift"}, "right")
end, nil, function()
hs.eventtap.keyStroke({"shift"}, "right")
end)
end
-- Function to unbind `hjkl` from arrow keys
function unmapControlFromArrows()
hs.hotkey.disableAll()
end
-- Function to toggle mappings
function toggleMappings()
if mappingsEnabled then
unmapControlFromArrows()
hs.alert.show("Control + hjkl as arrows disabled")
else
mapControlToArrows()
hs.alert.show("Control + hjkl as arrows enabled")
end
mappingsEnabled = not mappingsEnabled
end
-- Bind the toggle function to a hotkey (e.g., Ctrl+Shift+F1)
hs.hotkey.bind({"ctrl", "shift"}, "F1", toggleMappings)
-- Initial setup to enable mappings
toggleMappings()
|