diff --git a/atomacos/AXKeyCodeConstants.py b/atomacos/AXKeyCodeConstants.py deleted file mode 100644 index 8ed244c..0000000 --- a/atomacos/AXKeyCodeConstants.py +++ /dev/null @@ -1,261 +0,0 @@ -# Copyright (c) 2010 VMware, Inc. All Rights Reserved. - -# This file is part of ATOMac. - -# ATOMac is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by the Free -# Software Foundation version 2 and no later version. - -# ATOMac is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 -# for more details. - -# You should have received a copy of the GNU General Public License along with -# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin -# St, Fifth Floor, Boston, MA 02110-1301 USA. - -# Special keys -TAB = "" -RETURN = "" -SPACE = "" -ESCAPE = "" -CAPS_LOCK = "" -DELETE = "" -NUM_LOCK = "" -SCROLL_LOCK = "" -PAUSE = "" -BACKSPACE = "" -INSERT = "" - -# Cursor movement -UP = "" -DOWN = "" -LEFT = "" -RIGHT = "" -PAGE_UP = "" -PAGE_DOWN = "" -HOME = "" -END = "" - -# Numeric keypad -NUM_0 = "" -NUM_1 = "" -NUM_2 = "" -NUM_3 = "" -NUM_4 = "" -NUM_5 = "" -NUM_6 = "" -NUM_7 = "" -NUM_8 = "" -NUM_9 = "" -NUM_ENTER = "" -NUM_PERIOD = "" -NUM_PLUS = "" -NUM_MINUS = "" -NUM_MULTIPLY = "" -NUM_DIVIDE = "" - -# Function keys -F1 = "" -F2 = "" -F3 = "" -F4 = "" -F5 = "" -F6 = "" -F7 = "" -F8 = "" -F9 = "" -F10 = "" -F11 = "" -F12 = "" - -# Modifier keys -COMMAND_L = "" -SHIFT_L = "" -OPTION_L = "" -CONTROL_L = "" - -COMMAND_R = "" -SHIFT_R = "" -OPTION_R = "" -CONTROL_R = "" - -# Default modifier keys -> left: -COMMAND = COMMAND_L -SHIFT = SHIFT_L -OPTION = OPTION_L -CONTROL = CONTROL_L - - -# Define a dictionary representing characters mapped to their virtual key codes -# Lifted from the mappings found in kbdptr.h in the osxvnc project -# Mapping is: character -> virtual keycode for each character / symbol / key -# as noted below - -US_keyboard = { - # Letters - "a": 0, - "b": 11, - "c": 8, - "d": 2, - "e": 14, - "f": 3, - "g": 5, - "h": 4, - "i": 34, - "j": 38, - "k": 40, - "l": 37, - "m": 46, - "n": 45, - "o": 31, - "p": 35, - "q": 12, - "r": 15, - "s": 1, - "t": 17, - "u": 32, - "v": 9, - "w": 13, - "x": 7, - "y": 16, - "z": 6, - # Numbers - "0": 29, - "1": 18, - "2": 19, - "3": 20, - "4": 21, - "5": 23, - "6": 22, - "7": 26, - "8": 28, - "9": 25, - # Symbols - "!": 18, - "@": 19, - "#": 20, - "$": 21, - "%": 23, - "^": 22, - "&": 26, - "*": 28, - "(": 25, - ")": 29, - "-": 27, # Dash - "_": 27, # Underscore - "=": 24, - "+": 24, - "`": 50, # Backtick - "~": 50, - "[": 33, - "]": 30, - "{": 33, - "}": 30, - ";": 41, - ":": 41, - "'": 39, - '"': 39, - ",": 43, - "<": 43, - ".": 47, - ">": 47, - "/": 44, - "?": 44, - "\\": 42, - "|": 42, # Pipe - TAB: 48, # Tab: Shift-Tab sent for Tab - SPACE: 49, - " ": 49, # Space - # Characters that on the US keyboard require use with Shift - "upperSymbols": [ - "!", - "@", - "#", - "$", - "%", - "^", - "&", - "*", - "(", - ")", - "_", - "+", - "~", - "{", - "}", - ":", - '"', - "<", - ">", - "?", - "|", - ], -} - - -# Mapping for special (meta) keys -specialKeys = { - # Special keys - RETURN: 36, - DELETE: 117, - TAB: 48, - SPACE: 49, - ESCAPE: 53, - CAPS_LOCK: 57, - NUM_LOCK: 71, - SCROLL_LOCK: 107, - PAUSE: 113, - BACKSPACE: 51, - INSERT: 114, - # Cursor movement - UP: 126, - DOWN: 125, - LEFT: 123, - RIGHT: 124, - PAGE_UP: 116, - PAGE_DOWN: 121, - # Numeric keypad - NUM_0: 82, - NUM_1: 83, - NUM_2: 84, - NUM_3: 85, - NUM_4: 86, - NUM_5: 87, - NUM_6: 88, - NUM_7: 89, - NUM_8: 91, - NUM_9: 92, - NUM_ENTER: 76, - NUM_PERIOD: 65, - NUM_PLUS: 69, - NUM_MINUS: 78, - NUM_MULTIPLY: 67, - NUM_DIVIDE: 75, - # Function keys - F1: 122, - F2: 120, - F3: 99, - F4: 118, - F5: 96, - F6: 97, - F7: 98, - F8: 100, - F9: 101, - F10: 109, - F11: 103, - F12: 111, - # Modifier keys - COMMAND_L: 55, - SHIFT_L: 56, - OPTION_L: 58, - CONTROL_L: 59, - COMMAND_R: 54, - SHIFT_R: 60, - OPTION_R: 61, - CONTROL_R: 62, -} - -# Default keyboard layout -DEFAULT_KEYBOARD = US_keyboard diff --git a/atomacos/mixin/_input.py b/atomacos/mixin/_input.py index 8d263f0..589e425 100644 --- a/atomacos/mixin/_input.py +++ b/atomacos/mixin/_input.py @@ -1,7 +1,4 @@ import pyautogui -from atomacos.AXKeyCodeConstants import COMMAND, CONTROL, OPTION, SHIFT - -modifier_map = {COMMAND: "command", CONTROL: "ctrl", OPTION: "option", SHIFT: "shift"} class Mouse(object): @@ -47,9 +44,8 @@ def clickMouseButtonRight(self, coord, interval=0.0): def clickMouseButtonLeftWithMods(self, coord, modifiers, interval=None, clicks=1): """Click the left mouse button with modifiers pressed. - Parameters: coordinates to click; modifiers (list) (e.g. [SHIFT] or - [COMMAND, SHIFT] (assuming you've first used - from pyatom.AXKeyCodeConstants import *)) + Parameters: coordinates to click; modifiers (list) (e.g. ["shift"] or + ["command", "shift"]) Returns: None """ kb = Keyboard() @@ -117,9 +113,8 @@ def sendKey(self, keychr): def sendKeyWithModifiers(self, keychr, modifiers): """Send one character with modifiers pressed - Parameters: key character, modifiers (list) (e.g. [SHIFT] or - [COMMAND, SHIFT] (assuming you've first used - from pyatom.AXKeyCodeConstants import *)) + Parameters: key character, modifiers (list) (e.g. ["shift"] or + ["command", "shift"] """ self.pressModifiers(modifiers) self.sendKey(keychr) @@ -149,12 +144,12 @@ def sendKeys(self, keystr): def pressModifiers(self, modifiers): """Hold modifier keys (e.g. [Option]).""" for modifier in modifiers: - pyautogui.keyDown(modifier_map[modifier]) + pyautogui.keyDown(modifier) def releaseModifiers(self, modifiers): """Release modifier keys (e.g. [Option]).""" for modifier in modifiers: - pyautogui.keyUp(modifier_map[modifier]) + pyautogui.keyUp(modifier) class KeyboardMouseMixin(Mouse, Keyboard): diff --git a/tests/test_input.py b/tests/test_input.py index 5a03f29..78520c7 100644 --- a/tests/test_input.py +++ b/tests/test_input.py @@ -1,8 +1,6 @@ import subprocess import time -from atomacos.AXKeyCodeConstants import COMMAND, SHIFT - def calculate_center(size, position): center = (position.x + size.width / 2, position.y + size.height / 2) @@ -19,11 +17,11 @@ def test_types(finder_app): assert field.AXValue == "hello" field.sendKey("!") assert field.AXValue == "hello!" - field.sendKeyWithModifiers("a", [SHIFT]) + field.sendKeyWithModifiers("a", ["shift"]) assert field.AXValue == "hello!A" field.sendGlobalKey("@") assert field.AXValue == "hello!A@" - field.sendGlobalKeyWithModifiers("b", [SHIFT]) + field.sendGlobalKeyWithModifiers("b", ["shift"]) assert field.AXValue == "hello!A@B" @@ -47,7 +45,7 @@ def test_drag_folders(finder_app): subprocess.call("rm -rf {}".format(test_path), shell=True) subprocess.call("mkdir {}".format(test_path), shell=True) - finder_app.sendKeyWithModifiers("g", modifiers=[COMMAND, SHIFT]) + finder_app.sendKeyWithModifiers("g", modifiers=["command", "shift"]) end_time = time.time() + 10 while ( @@ -64,10 +62,10 @@ def test_drag_folders(finder_app): ): time.sleep(0.1) - finder_app.sendKeyWithModifiers("n", modifiers=[COMMAND, SHIFT]) + finder_app.sendKeyWithModifiers("n", modifiers=["command", "shift"]) finder_app.sendKeys("helloworld\n") - finder_app.sendKeyWithModifiers("n", modifiers=[COMMAND, SHIFT]) + finder_app.sendKeyWithModifiers("n", modifiers=["command", "shift"]) finder_app.sendKeys("helloworld2\n") file1 = finder_app.findFirstR(AXFilename="helloworld")