-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeymaps.lua
91 lines (78 loc) · 2.48 KB
/
keymaps.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
local utils = require('utils')
local REPEAT_FASTER = 10 * 1000
local REPEAT_SLOWER = 100 * 1000
local NO_REPEAT = -1
local function keyStroke(mod, key, repeatDelay)
hs.eventtap.event.newKeyEvent(mod, key, true):post()
if repeatDelay <= 0 then
repeatDelay = REPEAT_FASTER
end
hs.timer.usleep(repeatDelay)
hs.eventtap.event.newKeyEvent(mod, key, false):post()
end
local function keyStrokeSystem(key, repeatDelay)
hs.eventtap.event.newSystemKeyEvent(key, true):post()
if repeatDelay <= 0 then
repeatDelay = REPEAT_FASTER
end
hs.timer.usleep(repeatDelay)
hs.eventtap.event.newSystemKeyEvent(key, false):post()
end
-- Map sourceKey + sourceMod -> targetKey + targetMod
local function keymap(sourceKey, sourceMod, targetKey, targetMod, repeatDelay)
sourceMod = sourceMod or {}
repeatDelay = repeatDelay or REPEAT_FASTER
noRepeat = repeatDelay <= 0
local fn = nil
if targetMod == nil then
fn = hs.fnutils.partial(keyStrokeSystem, string.upper(targetKey), repeatDelay)
else
targetMod = utils.splitStr(targetMod, '+')
fn = hs.fnutils.partial(keyStroke, targetMod, targetKey, repeatDelay)
end
if noRepeat then
hs.hotkey.bind(sourceMod, sourceKey, fn, nil, nil)
else
hs.hotkey.bind(sourceMod, sourceKey, fn, nil, fn)
end
end
-- ------------------
-- move
-- ------------------
local arrows = {
b = 'left',
n = 'down',
p = 'up',
f = 'right'
}
for k, v in pairs(arrows) do
keymap(k, 'alt', v, '')
keymap(k, 'alt+ctrl', v, 'alt')
end
keymap('a', 'alt', 'home', '')
keymap('e', 'alt', 'end', '')
keymap('u', 'alt', 'pageup', '')
keymap('d', 'alt', 'pagedown', '')
-- ------------------
-- functionalities
-- ------------------
keymap('[', 'alt', 'tab', 'ctrl+shift', REPEAT_SLOWER)
keymap(']', 'alt', 'tab', 'ctrl', REPEAT_SLOWER)
keymap('q', 'alt', 'escape', '', NO_REPEAT)
-- ------------------
-- system
-- ------------------
-- not working
-- keymap('a', 'alt', 'CAPS_LOCK', nil, NO_REPEAT)
keymap('m', 'alt', 'PLAY', nil, NO_REPEAT)
keymap(',', 'alt+shift', 'REWIND', nil, NO_REPEAT)
keymap('.', 'alt+shift', 'FAST', nil, NO_REPEAT)
keymap(',', 'alt', 'SOUND_DOWN', nil)
keymap('.', 'alt', 'SOUND_UP', nil)
keymap('/', 'alt', 'MUTE', nil)
keymap('1', 'alt', 'PLAY', nil, NO_REPEAT)
keymap('2', 'alt', 'REWIND', nil, NO_REPEAT)
keymap('3', 'alt', 'FAST', nil, NO_REPEAT)
keymap('f1', 'alt', 'MUTE', nil)
keymap('f2', 'alt', 'SOUND_DOWN', nil)
keymap('f3', 'alt', 'SOUND_UP', nil)