Commit 480967a0 authored by talljosh's avatar talljosh

Pygame 2 uses different numbers from pygame 1 for keycodes. When loading a...

Pygame 2 uses different numbers from pygame 1 for keycodes. When loading a keymap file, convert them to the new number.
parent 9a84ee3996fe
......@@ -121,11 +121,19 @@ class KeyboardMapping(collections.UserDict):
# Update from string.
unmappedKeys = dict(self.virtualKeys)
for record in string.split('\n'):
lines = string.split('\n')
if lines[0] == '0:pygame2':
lines.pop(0)
load_map = lambda x: x
else:
load_map = convert_from_pygame1
for record in lines:
if record == '':
continue
key, vk = record.split(':')
self.data[int(key)] = vk
self.data[load_map(int(key))] = vk
if vk in unmappedKeys:
del unmappedKeys[vk]
......@@ -139,6 +147,7 @@ class KeyboardMapping(collections.UserDict):
Returns a configuration string for this keyboard mapping.
'''
records = ['%d:%s' % item for item in self.data.items()]
records.insert(0, '0:pygame2')
return '\n'.join(records)
def save(self, filename=None):
......@@ -155,3 +164,27 @@ class KeyboardMapping(collections.UserDict):
if v == action:
return k
raise KeyError(action)
PYGAME1_TO_PYGAME2 = {
318: 1073741896, 301: 1073741881, 12: 1073741980, 274: 1073741905, 279: 1073741901,
321: 1073742004, 282: 1073741882, 291: 1073741891, 292: 1073741892, 293: 1073741893,
294: 1073741928, 295: 1073741929, 296: 1073741930, 283: 1073741883,
284: 1073741884, 285: 1073741885, 286: 1073741886, 287: 1073741887,
288: 1073741888, 289: 1073741889, 290: 1073741890, 315: 1073741941,
278: 1073741898, 277: 1073741897, 256: 1073741922, 257: 1073741913,
258: 1073741914, 259: 1073741915, 260: 1073741916, 261: 1073741917,
262: 1073741918, 263: 1073741919, 264: 1073741920, 265: 1073741921,
267: 1073741908, 271: 1073741912, 272: 1073741927, 269: 1073741910,
268: 1073741909, 266: 1073741923, 270: 1073741911, 308: 1073742050,
306: 1073742048, 276: 1073741904, 310: 1073742051, 304: 1073742049,
311: 1073742051, 319: 1073741942, 313: 1073742081, 300: 1073741907,
281: 1073741902, 280: 1073741899, 19: 1073741896, 320: 1073741926,
316: 1073741894, 307: 1073742054, 305: 1073742052, 275: 1073741903,
309: 1073742055, 303: 1073742053, 312: 1073742055, 302: 1073741895,
317: 1073741978, 273: 1073741906,
}
def convert_from_pygame1(key):
return PYGAME1_TO_PYGAME2.get(key, key)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment