Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull #9

Merged
merged 3 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/Python_JEAutoControl.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 69 additions & 23 deletions .idea/workspace.xml

Large diffs are not rendered by default.

90 changes: 41 additions & 49 deletions je_auto_control/utils/action_executer/action_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,40 @@

event_dict = {
# mouse
"mouse_left": ("click_mouse", click_mouse),
"mouse_right": ("click_mouse", click_mouse),
"mouse_middle": ("click_mouse", click_mouse),
"mouse_table": ("mouse_table", mouse_table),
"position": ("position", position),
"press_mouse": ("press_mouse", press_mouse),
"release_mouse": ("release_mouse", release_mouse),
"scroll": ("scroll", scroll),
"set_position": ("set_position", set_position),
"special_table": ("special_table", special_table),
"mouse_left": click_mouse,
"mouse_right": click_mouse,
"mouse_middle": click_mouse,
"mouse_table": mouse_table,
"position": position,
"press_mouse": press_mouse,
"release_mouse": release_mouse,
"scroll": scroll,
"set_position": set_position,
"special_table": special_table,
# keyboard
"keys_table": ("keys_table", keys_table),
"type_key": ("type_key", type_key),
"press_key": ("press_key", press_key),
"release_key": ("release_key", release_key),
"check_key_is_press": ("check_key_is_press", check_key_is_press),
"write": ("write", write),
"hotkey": ("hotkey", hotkey),
"keys_table": keys_table,
"type_key": type_key,
"press_key": press_key,
"release_key": release_key,
"check_key_is_press": check_key_is_press,
"write": write,
"hotkey": hotkey,
# image
"locate_all_image": ("locate_all_image", locate_all_image),
"locate_image_center": ("locate_image_center", locate_image_center),
"locate_and_click": ("locate_and_click", locate_and_click),
"locate_all_image": locate_all_image,
"locate_image_center": locate_image_center,
"locate_and_click": locate_and_click,
# screen
"size": ("size", size),
"screenshot": ("screenshot", screenshot)
"size": size,
"screenshot": screenshot
}


def execute_event(action):
event = event_dict.get(action[0])
if event[0] in ["click_mouse"]:
event[1](action[0], action[1], action[2])
elif event[0] in ["type_key", "press_key", "release_key", "check_key_is_press", "write"]:
event[1](action[1])
elif event[0] in ["position", "record", "stop_record", "size"]:
event[1]()
elif event[0] in ["set_position", "screenshot"]:
event[1](action[1], action[2])
elif event[0] in ["locate_all_image", "locate_image_center", "press_mouse", "release_mouse"]:
event[1](action[1], action[2], action[3])
elif event[0] in ["scroll", "locate_and_click"]:
event[1](action[1], action[2], action[3], action[4])
if len(action) == 2:
event(**action[1])
else:
event()


def execute_action(action_list: list):
Expand Down Expand Up @@ -94,27 +86,27 @@ def execute_action(action_list: list):
test_list = None
if sys.platform in ["win32", "cygwin", "msys"]:
test_list = [
("type_key", 65),
("mouse_left", 500, 500),
("position", "position"),
("press_mouse", "mouse_left", 500, 500),
("release_mouse", "mouse_left", 500, 500),
["type_key", {"keycode": 65}],
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["position"],
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
]
elif sys.platform in ["linux", "linux2"]:
test_list = [
("type_key", 38),
("mouse_left", 500, 500),
("position", "position"),
("press_mouse", "mouse_left", 500, 500),
("release_mouse", "mouse_left", 500, 500)
["type_key", {"keycode": 38}],
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["position"],
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
]
elif sys.platform in ["darwin"]:
test_list = [
("type_key", 0x00),
("mouse_left", 500, 500),
("position", "position"),
("press_mouse", "mouse_left", 500, 500),
("release_mouse", "mouse_left", 500, 500)
["type_key", {"keycode": 0x00}],
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["position"],
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
]
print("\n\n")
print(execute_action(test_list))
6 changes: 3 additions & 3 deletions je_auto_control/wrapper/auto_control_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from je_auto_control.wrapper.auto_control_mouse import set_position


def locate_all_image(image, detect_threshold: float = 1, draw_image: bool = False):
def locate_all_image(image, detect_threshold: float = 1, draw_image: bool = False, **kwargs):
"""
:param image which image we want to find on screen
:param detect_threshold detect precision 0.0 ~ 1.0; 1 is absolute equal
Expand All @@ -22,7 +22,7 @@ def locate_all_image(image, detect_threshold: float = 1, draw_image: bool = Fals
raise ImageNotFoundException(cant_find_image)


def locate_image_center(image, detect_threshold: float = 1, draw_image: bool = False):
def locate_image_center(image, detect_threshold: float = 1, draw_image: bool = False, **kwargs):
"""
:param image which image we want to find on screen
:param detect_threshold detect precision 0.0 ~ 1.0; 1 is absolute equal
Expand All @@ -41,7 +41,7 @@ def locate_image_center(image, detect_threshold: float = 1, draw_image: bool = F
raise ImageNotFoundException(cant_find_image)


def locate_and_click(image, mouse_keycode: int, detect_threshold: float = 1, draw_image: bool = False):
def locate_and_click(image, mouse_keycode: [int, str], detect_threshold: float = 1, draw_image: bool = False, **kwargs):
"""
:param image which image we want to find on screen
:param mouse_keycode which mouse keycode we want to click
Expand Down
12 changes: 6 additions & 6 deletions je_auto_control/wrapper/auto_control_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from je_auto_control.wrapper.platform_wrapper import keys_table


def press_key(keycode: int, is_shift: bool = False):
def press_key(keycode: [int, str], is_shift: bool = False, **kwargs):
"""
:param keycode which keycode we want to press
:param is_shift shift is press?
Expand All @@ -33,7 +33,7 @@ def press_key(keycode: int, is_shift: bool = False):
raise AutoControlKeyboardException(keyboard_press_key)


def release_key(keycode: int, is_shift: bool = False):
def release_key(keycode: [int, str], is_shift: bool = False, **kwargs):
"""
:param keycode which keycode we want to release
:param is_shift shift is press?
Expand All @@ -52,7 +52,7 @@ def release_key(keycode: int, is_shift: bool = False):
raise AutoControlKeyboardException(keyboard_release_key)


def type_key(keycode: int, is_shift: bool = False):
def type_key(keycode: [int, str], is_shift: bool = False, **kwargs):
"""
:param keycode which keycode we want to type
:param is_shift shift is press?
Expand All @@ -64,7 +64,7 @@ def type_key(keycode: int, is_shift: bool = False):
raise AutoControlKeyboardException(keyboard_type_key)


def check_key_is_press(keycode: int):
def check_key_is_press(keycode: [int, str], **kwargs):
"""
:param keycode check key press?
"""
Expand All @@ -75,7 +75,7 @@ def check_key_is_press(keycode: int):
return keyboard_check.check_key_is_press(keycode=get_key_code)


def write(write_string: str, is_shift: bool = False):
def write(write_string: str, is_shift: bool = False, **kwargs):
"""
:param write_string while string not on write_string+1 type_key(string)
:param is_shift shift is press?
Expand All @@ -93,7 +93,7 @@ def write(write_string: str, is_shift: bool = False):
raise AutoControlKeyboardException(keyboard_write)


def hotkey(key_code_list: list, is_shift: bool = False):
def hotkey(key_code_list: list, is_shift: bool = False, **kwargs):
"""
:param key_code_list press and release all key on list and reverse
:param is_shift shift is press?
Expand Down
27 changes: 19 additions & 8 deletions je_auto_control/wrapper/auto_control_mouse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys

from je_auto_control.utils.je_auto_control_exception.exception_tag import mouse_click_mouse
from je_auto_control.utils.je_auto_control_exception.exception_tag import mouse_get_position
from je_auto_control.utils.je_auto_control_exception.exception_tag import table_cant_find_key
from je_auto_control.utils.je_auto_control_exception.exception_tag import mouse_press_mouse
from je_auto_control.utils.je_auto_control_exception.exception_tag import mouse_release_mouse
from je_auto_control.utils.je_auto_control_exception.exception_tag import mouse_set_position
Expand All @@ -22,7 +24,7 @@ def position():
raise AutoControlMouseException(mouse_get_position)


def set_position(x: int, y: int):
def set_position(x: int, y: int, **kwargs):
"""
:param x set position x
:param y set position y
Expand All @@ -33,14 +35,17 @@ def set_position(x: int, y: int):
raise AutoControlMouseException(mouse_set_position)


def press_mouse(mouse_keycode: int, x: int = None, y: int = None):
def press_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwargs):
"""
:param mouse_keycode which mouse keycode we want to press
:param x event x
:param y event y
"""
try:
mouse_keycode = mouse_table.get(mouse_keycode)
if type(mouse_keycode) is str:
mouse_keycode = mouse_table.get(mouse_keycode)
else:
pass
except Exception:
raise AutoControlCantFindKeyException(table_cant_find_key)
try:
Expand All @@ -57,14 +62,17 @@ def press_mouse(mouse_keycode: int, x: int = None, y: int = None):
raise AutoControlMouseException(mouse_press_mouse)


def release_mouse(mouse_keycode: int, x: int = None, y: int = None):
def release_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwargs):
"""
:param mouse_keycode which mouse keycode we want to release
:param x event x
:param y event y
"""
try:
mouse_keycode = mouse_table.get(mouse_keycode)
if type(mouse_keycode) is str:
mouse_keycode = mouse_table.get(mouse_keycode)
else:
pass
except Exception:
raise AutoControlCantFindKeyException(table_cant_find_key)
try:
Expand All @@ -84,14 +92,17 @@ def release_mouse(mouse_keycode: int, x: int = None, y: int = None):
raise AutoControlMouseException(mouse_release_mouse)


def click_mouse(mouse_keycode: int, x: int = None, y: int = None):
def click_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwargs):
"""
:param mouse_keycode which mouse keycode we want to click
:param x event x
:param y event y
"""
try:
mouse_keycode = mouse_table.get(mouse_keycode)
if type(mouse_keycode) is str:
mouse_keycode = mouse_table.get(mouse_keycode)
else:
pass
except Exception:
raise AutoControlCantFindKeyException(table_cant_find_key)
try:
Expand All @@ -108,7 +119,7 @@ def click_mouse(mouse_keycode: int, x: int = None, y: int = None):
raise AutoControlMouseException(mouse_click_mouse)


def scroll(scroll_value: int, x: int = None, y: int = None, scroll_direction: str = "scroll_down"):
def scroll(scroll_value: int, x: int = None, y: int = None, scroll_direction: str = "scroll_down", **kwargs):
""""
:param scroll_value scroll count
:param x event x
Expand Down
2 changes: 1 addition & 1 deletion je_auto_control/wrapper/auto_control_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def size():
raise AutoControlScreenException(screen_get_size)


def screenshot(file_path: str = None, region: list = None):
def screenshot(file_path: str = None, region: list = None, **kwargs):
"""
:param file_path screenshot file save path
:param region screenshot region
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="je_auto_control",
version="0.0.69",
version="0.0.71",
author="JE-Chen",
author_email="zenmailman@gmail.com",
description="auto testing",
Expand Down
2 changes: 1 addition & 1 deletion test/platform_independent/test/image/locate_and_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
mouse_keycode what mouse keycode you want to click
detect_threshold 0~1 , 1 is absolute equal
draw_image, mark the find target
draw_image, mark the find target
"""
image_data = locate_and_click("../test_source/test_template.png", mouse_keycode="mouse_left", detect_threshold=0.9,
draw_image=False)
Expand Down