diff --git a/pyautogui/__init__.py b/pyautogui/__init__.py index 43aebd5..60ce7c9 100644 --- a/pyautogui/__init__.py +++ b/pyautogui/__init__.py @@ -1535,7 +1535,7 @@ def isValidKey(key): Returns: bool: True if key is a valid value, False if not. """ - return platformModule.keyboardMapping.get(key, None) is not None + return platformModule.KEYBOARD_MAPPING.get(key, None) is not None @_genericPyAutoGUIChecks diff --git a/pyautogui/_pyautogui_osx.py b/pyautogui/_pyautogui_osx.py index 1a895f0..a044751 100644 --- a/pyautogui/_pyautogui_osx.py +++ b/pyautogui/_pyautogui_osx.py @@ -22,8 +22,8 @@ keyUp(), or press() into the code used for the OS-specific keyboard function. They should always be lowercase, and the same keys should be used across all OSes.""" -keyboardMapping = dict([(key, None) for key in pyautogui.KEY_NAMES]) -keyboardMapping.update({ +KEYBOARD_MAPPING = dict([(key, None) for key in pyautogui.KEY_NAMES]) +KEYBOARD_MAPPING.update({ 'a': 0x00, # kVK_ANSI_A 's': 0x01, # kVK_ANSI_S 'd': 0x02, # kVK_ANSI_D @@ -185,7 +185,7 @@ # add mappings for uppercase letters for c in 'abcdefghijklmnopqrstuvwxyz': - keyboardMapping[c.upper()] = keyboardMapping[c] + KEYBOARD_MAPPING[c.upper()] = KEYBOARD_MAPPING[c] # Taken from ev_keymap.h # http://www.opensource.apple.com/source/IOHIDFamily/IOHIDFamily-86.1/IOHIDSystem/IOKit/hidsystem/ev_keymap.h @@ -217,7 +217,7 @@ } def _keyDown(key): - if key not in keyboardMapping or keyboardMapping[key] is None: + if key not in KEYBOARD_MAPPING or KEYBOARD_MAPPING[key] is None: return if key in special_key_translate_table: @@ -226,7 +226,7 @@ def _keyDown(key): _normalKeyEvent(key, 'down') def _keyUp(key): - if key not in keyboardMapping or keyboardMapping[key] is None: + if key not in KEYBOARD_MAPPING or KEYBOARD_MAPPING[key] is None: return if key in special_key_translate_table: @@ -240,16 +240,16 @@ def _normalKeyEvent(key, upDown): try: if pyautogui.isShiftCharacter(key): - key_code = keyboardMapping[key.lower()] + key_code = KEYBOARD_MAPPING[key.lower()] event = Quartz.CGEventCreateKeyboardEvent(None, - keyboardMapping['shift'], upDown == 'down') + KEYBOARD_MAPPING['shift'], upDown == 'down') Quartz.CGEventPost(Quartz.kCGHIDEventTap, event) # Tiny sleep to let OS X catch up on us pressing shift time.sleep(pyautogui.DARWIN_CATCH_UP_TIME) else: - key_code = keyboardMapping[key] + key_code = KEYBOARD_MAPPING[key] event = Quartz.CGEventCreateKeyboardEvent(None, key_code, upDown == 'down') Quartz.CGEventPost(Quartz.kCGHIDEventTap, event) diff --git a/pyautogui/_pyautogui_win.py b/pyautogui/_pyautogui_win.py index f4119ac..36a9c3c 100644 --- a/pyautogui/_pyautogui_win.py +++ b/pyautogui/_pyautogui_win.py @@ -109,8 +109,8 @@ class _I(ctypes.Union): keyUp(), or press() into the code used for the OS-specific keyboard function. They should always be lowercase, and the same keys should be used across all OSes.""" -keyboardMapping = dict([(key, None) for key in pyautogui.KEY_NAMES]) -keyboardMapping.update({ +KEYBOARD_MAPPING = dict([(key, None) for key in pyautogui.KEY_NAMES]) +KEYBOARD_MAPPING.update({ 'backspace': 0x08, # VK_BACK '\b': 0x08, # VK_BACK 'super': 0x5B, #VK_LWIN @@ -244,7 +244,7 @@ class _I(ctypes.Union): # Populate the basic printable ascii characters. # https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-vkkeyscana for c in range(32, 128): - keyboardMapping[chr(c)] = ctypes.windll.user32.VkKeyScanA(ctypes.wintypes.WCHAR(chr(c))) + KEYBOARD_MAPPING[chr(c)] = ctypes.windll.user32.VkKeyScanA(ctypes.wintypes.WCHAR(chr(c))) def _keyDown(key): @@ -261,17 +261,17 @@ def _keyDown(key): Returns: None """ - if key not in keyboardMapping or keyboardMapping[key] is None: + if key not in KEYBOARD_MAPPING or KEYBOARD_MAPPING[key] is None: return needsShift = pyautogui.isShiftCharacter(key) """ - # OLD CODE: The new code relies on having all keys be loaded in keyboardMapping from the start. - if key in keyboardMapping.keys(): - vkCode = keyboardMapping[key] + # OLD CODE: The new code relies on having all keys be loaded in KEYBOARD_MAPPING from the start. + if key in KEYBOARD_MAPPING.keys(): + vkCode = KEYBOARD_MAPPING[key] elif len(key) == 1: - # note: I could use this case to update keyboardMapping to cache the VkKeyScan results, but I've decided not to just to make any possible bugs easier to reproduce. + # note: I could use this case to update KEYBOARD_MAPPING to cache the VkKeyScan results, but I've decided not to just to make any possible bugs easier to reproduce. vkCode = ctypes.windll.user32.VkKeyScanW(ctypes.wintypes.WCHAR(key)) if vkCode == -1: raise ValueError('There is no VK code for key "%s"' % (key)) @@ -279,7 +279,7 @@ def _keyDown(key): vkCode -= 0x100 needsShift = True """ - mods, vkCode = divmod(keyboardMapping[key], 0x100) + mods, vkCode = divmod(KEYBOARD_MAPPING[key], 0x100) for apply_mod, vk_mod in [(mods & 4, 0x12), (mods & 2, 0x11), (mods & 1 or needsShift, 0x10)]: #HANKAKU not supported! mods & 8 @@ -302,16 +302,16 @@ def _keyUp(key): Returns: None """ - if key not in keyboardMapping or keyboardMapping[key] is None: + if key not in KEYBOARD_MAPPING or KEYBOARD_MAPPING[key] is None: return needsShift = pyautogui.isShiftCharacter(key) """ - # OLD CODE: The new code relies on having all keys be loaded in keyboardMapping from the start. - if key in keyboardMapping.keys(): - vkCode = keyboardMapping[key] + # OLD CODE: The new code relies on having all keys be loaded in KEYBOARD_MAPPING from the start. + if key in KEYBOARD_MAPPING.keys(): + vkCode = KEYBOARD_MAPPING[key] elif len(key) == 1: - # note: I could use this case to update keyboardMapping to cache the VkKeyScan results, but I've decided not to just to make any possible bugs easier to reproduce. + # note: I could use this case to update KEYBOARD_MAPPING to cache the VkKeyScan results, but I've decided not to just to make any possible bugs easier to reproduce. vkCode = ctypes.windll.user32.VkKeyScanW(ctypes.wintypes.WCHAR(key)) if vkCode == -1: raise ValueError('There is no VK code for key "%s"' % (key)) @@ -319,7 +319,7 @@ def _keyUp(key): vkCode -= 0x100 needsShift = True """ - mods, vkCode = divmod(keyboardMapping[key], 0x100) + mods, vkCode = divmod(KEYBOARD_MAPPING[key], 0x100) for apply_mod, vk_mod in [(mods & 4, 0x12), (mods & 2, 0x11), (mods & 1 or needsShift, 0x10)]: #HANKAKU not supported! mods & 8 diff --git a/pyautogui/_pyautogui_x11.py b/pyautogui/_pyautogui_x11.py index 38c8463..4982e31 100644 --- a/pyautogui/_pyautogui_x11.py +++ b/pyautogui/_pyautogui_x11.py @@ -132,7 +132,7 @@ def _keyDown(key): Returns: None """ - if key not in keyboardMapping or keyboardMapping[key] is None: + if key not in KEYBOARD_MAPPING or KEYBOARD_MAPPING[key] is None: return if type(key) == int: @@ -142,12 +142,12 @@ def _keyDown(key): needsShift = pyautogui.isShiftCharacter(key) if needsShift: - fake_input(_display, X.KeyPress, keyboardMapping['shift']) + fake_input(_display, X.KeyPress, KEYBOARD_MAPPING['shift']) - fake_input(_display, X.KeyPress, keyboardMapping[key]) + fake_input(_display, X.KeyPress, KEYBOARD_MAPPING[key]) if needsShift: - fake_input(_display, X.KeyRelease, keyboardMapping['shift']) + fake_input(_display, X.KeyRelease, KEYBOARD_MAPPING['shift']) _display.sync() @@ -166,13 +166,13 @@ def _keyUp(key): Release a given character key. Also works with character keycodes as integers, but not keysyms. """ - if key not in keyboardMapping or keyboardMapping[key] is None: + if key not in KEYBOARD_MAPPING or KEYBOARD_MAPPING[key] is None: return if type(key) == int: keycode = key else: - keycode = keyboardMapping[key] + keycode = KEYBOARD_MAPPING[key] fake_input(_display, X.KeyRelease, keycode) _display.sync() @@ -182,14 +182,14 @@ def _keyUp(key): _display = Display(os.environ['DISPLAY']) -""" Information for keyboardMapping derived from PyKeyboard's special_key_assignment() function. +""" Information for KEYBOARD_MAPPING derived from PyKeyboard's special_key_assignment() function. The *KB dictionaries in pyautogui map a string that can be passed to keyDown(), keyUp(), or press() into the code used for the OS-specific keyboard function. They should always be lowercase, and the same keys should be used across all OSes.""" -keyboardMapping = dict([(key, None) for key in pyautogui.KEY_NAMES]) -keyboardMapping.update({ +KEYBOARD_MAPPING = dict([(key, None) for key in pyautogui.KEY_NAMES]) +KEYBOARD_MAPPING.update({ 'backspace': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('BackSpace')), '\b': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('BackSpace')), 'tab': _display.keysym_to_keycode(Xlib.XK.string_to_keysym('Tab')), @@ -318,4 +318,4 @@ def _keyUp(key): # Trading memory for time" populate winKB so we don't have to call VkKeyScanA each time. for c in """abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890""": - keyboardMapping[c] = _display.keysym_to_keycode(Xlib.XK.string_to_keysym(c)) + KEYBOARD_MAPPING[c] = _display.keysym_to_keycode(Xlib.XK.string_to_keysym(c))