Skip to content
Newer
Older
100644 132 lines (117 sloc) 3.74 KB
2678811 @sjl Add keyremap script.
authored Sep 27, 2012
1 # -*- coding: utf8 -*-
2 import string
3
4 greek = [
5 ('a', u'α' u'Α', u'', u''),
6 ('b', u'β' u'Β', u'', u''),
7 ('c', u'χ' u'Χ', u'', u''),
8 ('d', u'δ' u'Δ', u'', u''),
9 ('e', u'ε' u'Ε', u'', u''),
10 ('f', u'φ' u'Φ', u'', u''),
11 ('g', u'γ' u'Γ', u'', u''),
12 ('h', u'η' u'Η', u'', u''),
13 ('i', u'ι' u'Ι', u'', u''),
14 ('j', u'ϑ' u'Θ', u'', u''),
15 ('k', u'κ' u'Κ', u'', u''),
16 ('l', u'λ' u'Λ', u'', u''),
17 ('m', u'μ' u'Μ', u'', u''),
18 ('n', u'ν' u'Ν', u'', u''),
19 ('o', u'ο' u'Ο', u'', u''),
20 ('p', u'π' u'Π', u'', u''),
21 ('q', u'θ' u'Θ', u'', u''),
22 ('r', u'ρ' u'Ρ', u'', u''),
23 ('s', u'σ' u'Σ', u'', u''),
24 ('t', u'τ' u'Τ', u'', u''),
25 ('u', u'υ' u'Υ', u'', u''),
26 ('v', u'ς' u'Σ', u'', u''),
27 ('w', u'ω' u'Ω', u'', u''),
28 ('x', u'ξ' u'Ξ', u'', u''),
29 ('y', u'ψ' u'Ψ', u'', u''),
30 ('z', u'ζ' u'Ζ', u'', u''),
31 ]
32
33 math = [
34 ('a', u'', u'', u'', u''),
35 ('c', u'', u'', u'', u''),
36 ('e', u'', u'', u'', u''),
37 ('f', u'', u'', u'', u''),
38 ('i', u'', u'', u'', u''),
39 ('n', u'' , u'', u'', u''),
40 ('o', u'', u'', u'', u''),
41 ('r', u'', u'', u'', u''),
c3aa223 @sjl Moar.
authored Oct 3, 2012
42 # ('t', u'⊢', u'⊥', u'', u''),
2678811 @sjl Add keyremap script.
authored Sep 27, 2012
43 ('u', u'', u'', u'', u''),
44 ('x', u'', u'', u'', u''),
45 ('z', u'' , u'', u'', u''),
46 ('-', u'¬', u'', u'', u''),
47 ('=', u'', u'±', u'', u''),
48 ('/', u'÷', u'', u'', u''),
49 (',', u'' , u'', u'', u''),
50 ('.', u'·', u'', u'', u''),
51 ('0', u'', u'', u'', u''),
52 ('8', u'' , u'×', u'', u''),
53 ('`', u'' , u'', u'', u''),
54 ('[', u'', u'', u'', u''),
55 (']', u'', u'', u'', u''),
56 ('right', u'', u'', u'', u''),
57 ('left', u'', u'', u'', u''),
58 ('up', u'', u'', u'', u''),
59 ('down', u'', u'', u'', u''),
60 ]
61
62 def get_keycode(c):
63 if c in string.letters:
64 return c
65 elif c in string.digits:
66 return 'KEY_' + c
67 else:
68 return {
69 '-': 'MINUS',
70 '=': 'EQUAL',
71 '/': 'SLASH',
72 '\\': 'BACKSLASH',
73 '.': 'DOT',
74 ',': 'COMMA',
75 "'": 'QUOTE',
76 ';': 'SEMICOLON',
77 '[': 'BRACKET_LEFT',
78 ']': 'BRACKET_RIGHT',
79 '`': 'BACKQUOTE',
80 'left': 'CURSOR_LEFT',
81 'right': 'CURSOR_RIGHT',
82 'down': 'CURSOR_DOWN',
83 'up': 'CURSOR_UP',
84 }[c]
85
86 def get_line(c):
87 line_template = r'''KeyCode::%s, ModifierFlag::OPTION_L,'''
88 key = get_keycode(c)
89 return line_template % key
90
91 def get_codepoint(c):
92 r = repr(c)
93 if len(r) == 7:
94 return '00' + r[-3:-1].upper()
95 else:
96 return r[-5:-1].upper()
97
98 def get_chunk(source_key, dest_char, mod, buckies):
99 modifier_chunks = ['ModifierFlag::EXTRA%d'% mod]
100 modifier_chunks.extend(buckies)
101 modifier = ' | '.join(modifier_chunks)
102
103 codepoint = get_codepoint(dest_char)
104 lines = '\n'.join(get_line(c) for c in codepoint)
105
106 return r'''
107 <autogen>
108 --KeyToKey--
109 KeyCode::%s, %s,
110 %s
111 </autogen>
112 ''' % (source_key, modifier, lines)
113
114 def for_map(m, modifier):
115 for k, bare, shift, ctrl, shiftctrl in m:
116 k = get_keycode(k).upper()
117
118 if shiftctrl:
119 print get_chunk(k, shiftctrl, modifier, ['VK_CONTROL', 'VK_SHIFT'])
120
121 if shift:
122 print get_chunk(k, shift, modifier, ['VK_SHIFT'])
123
124 if ctrl:
125 print get_chunk(k, ctrl, modifier, ['VK_CONTROL'])
126
127 if bare:
128 print get_chunk(k, bare, modifier, [])
129
130 # for_map(greek, 4)
131 for_map(math, 3)
Something went wrong with that request. Please try again.