-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathconvert_km.py
56 lines (49 loc) · 1.53 KB
/
convert_km.py
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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""This script convert xrdp's km-xxxx.ini keymap file to vnc2rdp code"""
import re
import sys
def main():
if len(sys.argv) != 2:
print 'Usage: %s FILE' % sys.argv[0]
km_filename = sys.argv[1]
km_file = open(km_filename, 'r')
km = {
'noshift': [0, 0, 0, 0, 0, 0, 0, 0],
'shift': [0, 0, 0, 0, 0, 0, 0, 0],
'altgr': [0, 0, 0, 0, 0, 0, 0, 0],
'capslock': [0, 0, 0, 0, 0, 0, 0, 0],
'shiftcapslock': [0, 0, 0, 0, 0, 0, 0, 0]
}
lines = km_file.readlines()
keysym_rx = re.compile(r'^Key.*=(?P<keysym>.*):.*$')
for line in lines:
if line.startswith('['):
section = line[1:len(line) - 2]
continue
if not keysym_rx.match(line):
continue
keysym = int(keysym_rx.sub(r'\g<keysym>', line))
km[section].append(keysym)
for i, key in enumerate(km.keys()):
print '.%s = {' % key
for j, keysym in enumerate(km[key]):
if j % 8 == 0:
prefix = '\t'
else:
prefix = ''
if j != len(km[key]) - 1:
suffix = ','
if (j + 1) % 8 != 0:
suffix += ' '
else:
suffix += '\n'
else:
suffix = '\n'
sys.stdout.write('%s0x%04x%s' % (prefix, keysym, suffix))
if i == len(km.keys()) - 1:
print '}'
else:
print '},'
if __name__ == '__main__':
main()