-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyper.lua
executable file
·104 lines (89 loc) · 3.76 KB
/
hyper.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
92
93
94
95
96
97
98
99
100
101
102
103
104
-----------------------------------------------------------------------------------
-- File: hyper.lua
-- Author: Joaquín Cuitiño
-- Adapted from: https://github.com/jhkuperus/dotfiles/blob/master/hammerspoon/hyper.lua
-- License: MIT
-----------------------------------------------------------------------------------
-- To use Hyper in your init.lua script, import it and adapt this example to
-- your needs:
--
-- local hyper = require("hyper")
-- hyper.install("F18")
-- hyper.bindkey("r", hs.reload)
--
-- The above three lines initialize Hyper to respond to F18 key-events and binds
-- Hyper+r to Hammerspoon Reload (easy way to refresh Hammerspoon"s config)
-- Hyper mode needs to be bound to a key. Here we are binding
-- it to F17, because this is yet another key that"s unused.
-- Why not F18? We will use key-events from F18 to turn hyper
-- mode on and off. Using F17 as the modal and source of key
-- events, will result in a very jittery Hyper mode.
--
-- If the hyper key is pressed but not triggered (no shortcut is executed)
-- then an "ESCAPE" keypress is emitted. This was added so we can replace the
-- Caps Lock key for Escape in touchbar MacBooks.
local This = {}
This.hyperMode = hs.hotkey.modal.new({}, "F17")
-- Enter Hyper Mode when F18 (Hyper) is pressed
function enterHyperMode()
This.hyperMode.triggered = false
This.hyperMode:enter()
end
-- Leave Hyper Mode when F18 (Hyper) is pressed
function exitHyperMode()
This.hyperMode:exit()
if not This.hyperMode.triggered then
-- hs.eventtap.keyStroke({}, "ESCAPE")
hs.hid.capslock.toggle()
end
end
-- Binds handler function to Hyper+[modifiers]+key
function This.bind(mods, key, handler)
superHandler = function()
This.hyperMode.triggered = true
-- hs.alert("hyper", nil, hs.screen.mainScreen(), 1)
handler()
end
This.hyperMode:bind(mods, key, superHandler)
end
-- Binds handler function to Hyper+key
function This.bindKey(key, handler)
This.bind({}, key, handler)
end
-- Binds handler function to Hyper+Shift+key
function This.bindShiftKey(key, handler)
This.bind({"shift"}, key, handler)
end
-- Binds handler function to Hyper+Command+Shift+key
function This.bindCommandShiftKey(key, handler)
This.bind({"command", "shift"}, key, handler)
end
function This.remap(initialMods, initialKey, mods, key)
handler = function()
hs.eventtap.keyStroke(mods, key, 1000)
end
This.bind(initialMods, initialKey, handler)
end
function This.remapKey(initialKey, key)
This.remap({}, initialKey, {}, key)
end
-- Binds the enter/exit functions of the Hyper modal to all combinations of modifiers
function This.install(hotKey)
hs.hotkey.bind({}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"shift"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"ctrl"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"ctrl", "shift"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"cmd"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"cmd", "shift"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"cmd", "ctrl"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"cmd", "ctrl", "shift"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"alt"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"alt", "shift"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"alt", "ctrl"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"alt", "ctrl", "shift"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"alt", "cmd"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"alt", "cmd", "shift"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"alt", "cmd", "ctrl"}, hotKey, enterHyperMode, exitHyperMode)
hs.hotkey.bind({"alt", "cmd", "shift", "ctrl"}, hotKey, enterHyperMode, exitHyperMode)
end
return This