Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Commit

Permalink
feat(input): Delete AXKeyCodeConstants
Browse files Browse the repository at this point in the history
Deleted AXKeyCodeConstants in favor of just using pyautogui as the input api

BREAKING CHANGE: Deleted AXKeyCodeConstants means modifiers are no longer imported. Refer to
pyautogui docs to get modifier strings
  • Loading branch information
daveenguyen committed Mar 22, 2019
1 parent 378a66c commit 6b21430
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 279 deletions.
261 changes: 0 additions & 261 deletions atomacos/AXKeyCodeConstants.py

This file was deleted.

17 changes: 6 additions & 11 deletions atomacos/mixin/_input.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 5 additions & 7 deletions tests/test_input.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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"


Expand All @@ -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 (
Expand All @@ -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")
Expand Down

0 comments on commit 6b21430

Please sign in to comment.