Last active
December 23, 2021 14:59
-
-
Save heathhenley/9e5de8c027dd1d02881aa1c4c8eaafb1 to your computer and use it in GitHub Desktop.
Try to register hotkeys to see which are available (out of the options SonaSoft allows)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import itertools | |
| import ctypes | |
| kNO_REPEAT = 0x4000 | |
| MODIFIERS = dict(ctrl=0x0002 | kNO_REPEAT, | |
| alt=0x0001 | kNO_REPEAT, | |
| shift=0x0004 | kNO_REPEAT) | |
| def hotkey_is_available(mods, vkey): | |
| hotkey_available = False | |
| try: | |
| if ctypes.windll.user32.RegisterHotKey(None, 1, mods, vkey): | |
| hotkey_available = True | |
| except: #pylint: disable=bare-except | |
| pass | |
| finally: | |
| ctypes.windll.user32.UnregisterHotKey(None, 1) | |
| return hotkey_available | |
| def generate_all_modifier_combos(basic_modifiers): | |
| mod_codes = [] | |
| for n in range(1, len(basic_modifiers.values())+1): | |
| for mods in itertools.combinations(basic_modifiers.values(), n): | |
| mod = mods[0] | |
| for m in mods: | |
| mod = mod | m | |
| mod_codes.append(mod) | |
| return mod_codes | |
| def to_readable_modifier_keys(modifier): | |
| text_modifiers = [] | |
| for key, value in MODIFIERS.items(): | |
| if value & modifier == value: | |
| text_modifiers.append(key) | |
| return text_modifiers | |
| def get_vkey_code_map(): | |
| # Digits and numbers | |
| key_map = {} | |
| for i in range(0, 10): | |
| key_map[ord(str(i))] = i | |
| for i in range(ord('A'), ord('Z')+1): | |
| key_map[i] = chr(i+32) | |
| # Special keys | |
| key_map[8] = "tab" | |
| key_map[9] = "backspace" | |
| key_map[37] = "left" | |
| key_map[38] = "up" | |
| key_map[39] = "right" | |
| key_map[40] = "down" | |
| key_map[106] = "numpad_mult" | |
| key_map[107] = "numpad_add" | |
| key_map[108] = "numpad_separator" | |
| key_map[109] = "numpad_subtract" | |
| key_map[110] = "numpad_decimal" | |
| key_map[111] = "numpad_divide" | |
| for i in range(96, 106): | |
| n = i - 96 | |
| key_map[i] = f"numpad{n}" | |
| for i in range(112, 128): | |
| n = i - 112 + 1 | |
| key_map[i] = f"f{n}" | |
| return key_map | |
| def main(): | |
| vkeys_map = get_vkey_code_map() | |
| mod_list = generate_all_modifier_combos(MODIFIERS) | |
| valid_hotkeys = [] | |
| invalid_hotkeys = [] | |
| for mods in mod_list: | |
| for vkey in vkeys_map: | |
| if hotkey_is_available(mods, vkey): | |
| valid_hotkeys.append((mods, vkey)) | |
| else: | |
| invalid_hotkeys.append((mods, vkey)) | |
| if not invalid_hotkeys: | |
| print("No assigned hotkeys found") | |
| for mods, vkey in invalid_hotkeys: | |
| s = " + ".join([x for x in to_readable_modifier_keys(mods)]) | |
| print(f"Hotkey assigned: {s}, {vkeys_map[vkey]}") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment