Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 75 lines (64 sloc) 2.263 kb
b80bef2 @rmm5t Added reference to cmd-key-happy source
authored
1 -- See https://github.com/aim-stuff/cmd-key-happy
2
0600292 @rmm5t cmd-key-happy configuration
authored
3 function Set(t)
4 local s = {}
5 for _,v in pairs(t) do s[v] = true end
6 return s
7 end
8
9 function set_contains(t, e)
10 return t[e]
11 end
12
13 -- The set of global shortcuts we don't want to swap cmd/alt.
14
15 global_excludes = Set{ "shift-cmd-tab",
16 "cmd-tab",
17 "cmd-space",
18 "shift-cmd-space",
c87f328 @rmm5t [cmd-key-happy] Added ⌘, to the global excludes
authored
19 "cmd-,",
0600292 @rmm5t cmd-key-happy configuration
authored
20 }
21
22 -- The set of apps we want to consider swapping keys for, with some
23 -- notable exclusions. The exclusion means that a "cmd-w" will do the
24 -- normal OS Terminal behaviour. If you omit items then you would
25 -- have to use "alt-w" to close a terminal window.
26
27 terminal_excludes = Set{ "shift-cmd-[",
28 "shift-cmd-]",
29 "cmd-c",
30 "cmd-v",
31 "cmd-w",
32 "cmd-t",
33 "cmd-n",
34 "cmd-`",
171e909 @rmm5t Added cmd-k to the list of cmd-key-happy ignores
authored
35 "cmd-k",
0600292 @rmm5t cmd-key-happy configuration
authored
36 }
37
38 apps = {
39 Terminal = { exclude = terminal_excludes },
40 iTerm = { exclude = terminal_excludes },
41 }
42
43 -- Return true to swap cmd/alt, otherwise false.
44
45 -- This function is passed a table comprising the following keys:
46 --
47 -- key_str_seq key sequence (e.g., "shift-cmd-e")
48 -- alt true if the alt key was pressed
49 -- fn true if the fn key was pressed
50 -- control true if the control key was pressed
51 -- shift true if the shift key was pressed
52 -- cmd true if the command key was pressed
53 -- keycode numeric virtual keycode (e.g., 48)
54 -- appname the frontmost application (e.g., Terminal)
55 --
56 -- The order of the modifier keys in key-str-eq is always:
57 -- shift control alt cmd fn, separated by a hyphen ("-").
58
59 function swap_keys(t)
60 -- for i,v in pairs(t) do print(i,v) end
61 -- print(t.appname)
62 if set_contains(global_excludes, t.key_str_seq) then
63 return false
64 end
65 if not apps[t.appname] then
66 return false
67 end
68 local excludes = apps[t.appname]["exclude"]
69 if set_contains(excludes, t.key_str_seq) then
70 -- print("exluding: ", t.key_str_seq)
71 return false
72 end
73 return true
74 end
Something went wrong with that request. Please try again.