forked from frobware/cmd-key-happy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example-rcfile.lua
77 lines (69 loc) · 2.24 KB
/
example-rcfile.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
function Set(t)
local s = {}
for _,v in pairs(t) do s[v] = true end
return s
end
function set_contains(t, e)
return t[e]
end
-- The set of global shortcuts we don't want to swap cmd/alt.
global_excludes = Set{ "shift-cmd-tab",
"cmd-tab" }
-- The set of apps we want to consider swapping keys for, with some
-- notable exclusions. The exclusion means that a "cmd-w" will do the
-- normal OS Terminal behaviour. If you omit items then you would
-- have to use "alt-w" to close a terminal window.
apps = {
Terminal = { exclude = Set{ "shift-cmd-[",
"shift-cmd-]",
"cmd-c",
"cmd-v",
"cmd-w",
"cmd-1",
"cmd-2",
"cmd-3",
"cmd-t",
"cmd-n",
"cmd-`",
} },
Eclipse = { exclude = {} },
Xcode = { exclude = {} },
TextMate = { exclude = Set { "cmd-1",
"cmd-2",
"cmd-3",
"cmd-4",
"cmd-t" ,
"cmd-fn-right",
"cmd-fn-left",
} },
}
-- Return true to swap cmd/alt, otherwise false.
-- This function is passed a table comprising the following keys:
--
-- key_str_seq key sequence (e.g., "shift-cmd-e")
-- alt true if the alt key was pressed
-- fn true if the fn key was pressed
-- control true if the control key was pressed
-- shift true if the shift key was pressed
-- cmd true if the command key was pressed
-- keycode numeric virtual keycode (e.g., 48)
-- appname the frontmost application (e.g., Terminal)
--
-- The order of the modifier keys in key-str-eq is always:
-- shift control alt cmd fn, separated by a hyphen ("-").
function swap_keys(t)
-- for i,v in pairs(t) do print(i,v) end
-- print(t.appname)
if set_contains(global_excludes, t.key_str_seq) then
return false
end
if not apps[t.appname] then
return false
end
local excludes = apps[t.appname]["exclude"]
if set_contains(excludes, t.key_str_seq) then
-- print("exluding: ", t.key_str_seq)
return false
end
return true
end