def _setup_name_tables():
with tables_lock:<EOL><INDENT>if to_name: return<EOL>all_scan_codes = [(sc, user32.MapVirtualKeyExW(sc, MAPVK_VSC_TO_VK_EX, <NUM_LIT:0>)) for sc in range(<NUM_LIT>)]<EOL>all_vks =        [(user32.MapVirtualKeyExW(vk, MAPVK_VK_TO_VSC_EX, <NUM_LIT:0>), vk) for vk in range(<NUM_LIT>)]<EOL>for scan_code, vk in all_scan_codes + all_vks:<EOL><INDENT>if (scan_code, vk, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>) in to_name:<EOL><INDENT>continue<EOL><DEDENT>if scan_code not in scan_code_to_vk:<EOL><INDENT>scan_code_to_vk[scan_code] = vk<EOL><DEDENT>for extended in [<NUM_LIT:0>, <NUM_LIT:1>]:<EOL><INDENT>for modifiers in distinct_modifiers:<EOL><INDENT>entry = (scan_code, vk, extended, modifiers)<EOL>names = list(get_event_names(*entry))<EOL>if names:<EOL><INDENT>lowercase_names = [name.lower() for name in names]<EOL>to_name[entry] = names + lowercase_names<EOL>for i, name in enumerate(map(normalize_name, names + lowercase_names)):<EOL><INDENT>from_name[name].append((i, entry))<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>for extended in [<NUM_LIT:0>, <NUM_LIT:1>]:<EOL><INDENT>for modifiers in distinct_modifiers:<EOL><INDENT>to_name[(<NUM_LIT>, <NUM_LIT>, extended, modifiers)] = ['<STR_LIT>']<EOL>from_name['<STR_LIT>'].append((<NUM_LIT:1>, (<NUM_LIT>, <NUM_LIT>, extended, modifiers)))<EOL><DEDENT><DEDENT><DEDENT>modifiers_preference = defaultdict(lambda: <NUM_LIT:10>)<EOL>modifiers_preference.update({(): <NUM_LIT:0>, ('<STR_LIT>',): <NUM_LIT:1>, ('<STR_LIT>',): <NUM_LIT:2>, ('<STR_LIT>',): <NUM_LIT:3>, ('<STR_LIT>',): <NUM_LIT:4>})<EOL>def order_key(line):<EOL><INDENT>i, entry = line<EOL>scan_code, vk, extended, modifiers = entry<EOL>return modifiers_preference[modifiers], i, extended, vk, scan_code<EOL><DEDENT>for name, entries in list(from_name.items()):<EOL><INDENT>from_name[name] = sorted(set(entries), key=order_key)<EOL><DEDENT>
Ensures the scan code/virtual key code/name translation tables are
filled.