Skip to content
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
6 changes: 5 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# keyboard test
- run:
command: python ./circle_ci_test/keyboard/keyboard_type_test.py
name: keyboard_test
name: keyboard_type_test
- run:
command: python ./circle_ci_test/keyboard/keyboard_write_test.py
name: keyboard_write_test
Expand Down Expand Up @@ -75,6 +75,10 @@ jobs:
- run:
command: python ./circle_ci_test/json/json_test.py
name: json_test
# timeout
- run:
command: python ./circle_ci_test/timeout/timeout_test.py
name: timeout_test

workflows:
main:
Expand Down
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/discord.xml

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.

144 changes: 97 additions & 47 deletions .idea/workspace.xml

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions circle_ci_test/timeout/timeout_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from itertools import count
from time import sleep

from je_auto_control import multiprocess_timeout

counter = count(1)


def time_not_out_function():
print("Hello")


def time_out_test_function():
while True:
sleep(1)
print(next(counter))


if __name__ == "__main__":
print(multiprocess_timeout(time_not_out_function, 5))
print(multiprocess_timeout(time_out_test_function, 5))
3 changes: 3 additions & 0 deletions je_auto_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@
from je_auto_control.utils.action_executer.action_executor import execute_action
from je_auto_control.utils.action_file.json_file import read_action_json
from je_auto_control.utils.action_file.json_file import write_action_json

# timeout
from je_auto_control.utils.timeout.multiprocess_timeout import multiprocess_timeout
47 changes: 13 additions & 34 deletions je_auto_control/utils/je_auto_control_exception/exception_tag.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,45 @@
"""
error tags
"""
# error tags
je_auto_control_error = "Auto control error"
je_auto_control_critical_exit_error = "Auto control critical exit error"
"""
os tags
"""
# os tags
linux_import_error = "should be only loaded on linux"
osx_import_error = "should be only loaded on MacOS"
windows_import_error = "should be only loaded on windows"
"""
keyboard tags
"""
macos_record_error = "macos can't use recorder"
# keyboard tags
keyboard_error = "Auto control keyboard error"
keyboard_press_key = "keyboard press key error"
keyboard_release_key = "keyboard release key error"
keyboard_type_key = "keyboard type key error"
keyboard_write = "keyboard write error"
keyboard_write_cant_find = "keyboard write error can't find key"
keyboard_hotkey = "keyboard hotkey error"
"""
mouse tags
"""
# mouse tags
mouse_error = "Auto control mouse error"
mouse_get_position = "mouse get position error"
mouse_set_position = "mouse set position error"
mouse_press_mouse = "mouse press mouse error"
mouse_release_mouse = "mouse release key error"
mouse_click_mouse = "mouse click mouse error"
mouse_scroll = "mouse scroll error"
"""
screen tags
"""
# screen tags
screen_error = "Auto control screen error"
screen_get_size = "screen get size error"
screen_screenshot = "screen screenshot error"
"""
table tags
"""
# table tags
table_cant_find_key = "can't find key error"
"""
image tags
"""
# image tags
cant_find_image = "can't find image"
find_image_error_variable = "variable error"
"""
listener tags
"""
# listener tags
listener_error = "Auto control listener error"
"""
record tags
"""
# record tags
record_queue_error = "can't get record queue it's none are you using stop record before record"
record_not_found_action_error = "record action not found"
"""
json action file tag
"""
# json action file tag
cant_execute_action_error = "can't execute action"
cant_find_json_error = "can't find json file"
cant_save_json_error = "can't save json file"
action_is_null_error = "json action is null"
"""
macos error tag
"""
macos_record_error = "macos can't use recorder"
# timeout tag
timeout_need_on_main_error = "should put timeout function on main"
35 changes: 12 additions & 23 deletions je_auto_control/utils/je_auto_control_exception/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
"""
general
"""


# general
class AutoControlException(Exception):
pass


"""
Keyboard
"""
# Keyboard


class AutoControlKeyboardException(AutoControlException):
Expand All @@ -20,45 +14,35 @@ class AutoControlCantFindKeyException(AutoControlException):
pass


"""
Mouse
"""
# Mouse


class AutoControlMouseException(AutoControlException):
pass


"""
Screen
"""
# Screen


class AutoControlScreenException(AutoControlException):
pass


"""
Image detect
"""
# Image detect


class ImageNotFoundException(AutoControlException):
pass


"""
Record
"""
# Record


class AutoControlRecordException(AutoControlException):
pass


"""
Execute action
"""
# Execute action


class AutoControlJsonActionException(AutoControlException):
Expand All @@ -71,3 +55,8 @@ class AutoControlActionNullException(AutoControlException):

class AutoControlActionException(AutoControlException):
pass


# timeout
class AutoControlTimeoutException(AutoControlException):
pass
1 change: 1 addition & 0 deletions je_auto_control/utils/timeout/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from je_auto_control.utils.timeout import *
17 changes: 17 additions & 0 deletions je_auto_control/utils/timeout/multiprocess_timeout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from multiprocessing import Process
from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlTimeoutException
from je_auto_control.utils.je_auto_control_exception.exception_tag import timeout_need_on_main_error


def multiprocess_timeout(check_function, time: int):
try:
new_process = Process(target=check_function)
new_process.start()
new_process.join(timeout=time)
except AutoControlTimeoutException:
raise AutoControlTimeoutException(timeout_need_on_main_error)
new_process.terminate()
if new_process.exitcode is None:
return "timeout"
else:
return "success"
14 changes: 11 additions & 3 deletions je_auto_control/wrapper/auto_control_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def press_key(keycode: [int, str], is_shift: bool = False, **kwargs):
keyboard.press_key(keycode)
elif sys.platform in ["darwin"]:
keyboard.press_key(keycode, is_shift=is_shift)
return str(keycode)
except Exception:
raise AutoControlKeyboardException(keyboard_press_key)

Expand All @@ -48,6 +49,7 @@ def release_key(keycode: [int, str], is_shift: bool = False, **kwargs):
keyboard.release_key(keycode)
elif sys.platform in ["darwin"]:
keyboard.release_key(keycode, is_shift=is_shift)
return str(keycode)
except Exception:
raise AutoControlKeyboardException(keyboard_release_key)

Expand All @@ -60,6 +62,7 @@ def type_key(keycode: [int, str], is_shift: bool = False, **kwargs):
try:
press_key(keycode, is_shift)
release_key(keycode, is_shift)
return str(keycode)
except AutoControlKeyboardException:
raise AutoControlKeyboardException(keyboard_type_key)

Expand All @@ -81,14 +84,16 @@ def write(write_string: str, is_shift: bool = False, **kwargs):
:param is_shift shift is press?
"""
try:
record_write_string = ""
for single_string in write_string:
try:
if keys_table.get(single_string) is not None:
type_key(single_string, is_shift)
record_write_string = "".join([record_write_string, type_key(single_string, is_shift)])
else:
raise AutoControlKeyboardException(keyboard_write_cant_find)
except AutoControlKeyboardException:
print(keyboard_write_cant_find, single_string, sep="\t", file=sys.stderr)
return record_write_string
except AutoControlKeyboardException:
raise AutoControlKeyboardException(keyboard_write)

Expand All @@ -99,10 +104,13 @@ def hotkey(key_code_list: list, is_shift: bool = False, **kwargs):
:param is_shift shift is press?
"""
try:
record_hotkey_press_string = ""
record_hotkey_release_string = ""
for key in key_code_list:
press_key(key, is_shift)
record_hotkey_press_string = ",".join([record_hotkey_press_string, press_key(key, is_shift)])
key_code_list.reverse()
for key in key_code_list:
release_key(key, is_shift)
record_hotkey_release_string = ",".join([record_hotkey_release_string, release_key(key, is_shift)])
return record_hotkey_press_string, record_hotkey_release_string
except AutoControlKeyboardException:
raise AutoControlKeyboardException(keyboard_hotkey)
5 changes: 5 additions & 0 deletions je_auto_control/wrapper/auto_control_mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def set_position(x: int, y: int, **kwargs):
"""
try:
mouse.set_position(x=x, y=y)
return x, y
except Exception:
raise AutoControlMouseException(mouse_set_position)

Expand Down Expand Up @@ -58,6 +59,7 @@ def press_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwarg
mouse.press_mouse(mouse_keycode)
elif sys.platform in ["darwin"]:
mouse.press_mouse(x, y, mouse_keycode)
return mouse_keycode, x, y
except Exception:
raise AutoControlMouseException(mouse_press_mouse)

Expand Down Expand Up @@ -88,6 +90,7 @@ def release_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwa
mouse.release_mouse(mouse_keycode)
elif sys.platform in ["darwin"]:
mouse.release_mouse(x, y, mouse_keycode)
return mouse_keycode, x, y
except Exception:
raise AutoControlMouseException(mouse_release_mouse)

Expand Down Expand Up @@ -115,6 +118,7 @@ def click_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwarg
raise AutoControlMouseException(mouse_get_position)
try:
mouse.click_mouse(mouse_keycode, x, y)
return mouse_keycode, x, y
except Exception:
raise AutoControlMouseException(mouse_click_mouse)

Expand Down Expand Up @@ -157,5 +161,6 @@ def scroll(scroll_value: int, x: int = None, y: int = None, scroll_direction: st
elif sys.platform in ["linux", "linux2"]:
scroll_direction = special_table.get(scroll_direction)
mouse.scroll(scroll_value, scroll_direction)
return scroll_value, scroll_direction
except Exception:
raise AutoControlMouseException(mouse_click_mouse)
4 changes: 2 additions & 2 deletions je_auto_control/wrapper/auto_control_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def stop_record_keyboard():
def record():
if sys.platform == "darwin":
raise AutoControlException(macos_record_error)
recorder.record()
return recorder.record()


def stop_record():
Expand All @@ -49,7 +49,7 @@ def stop_record():
if action_queue is None:
raise AutoControlJsonActionException
action_list = list(action_queue.queue)
execute_action(action_list)
return execute_action(action_list)


if __name__ == "__main__":
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.71",
version="0.0.73",
author="JE-Chen",
author_email="[email protected]",
description="auto testing",
Expand Down
2 changes: 1 addition & 1 deletion test/platform_independent/test/keyboard/hotkey_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from je_auto_control import hotkey

if sys.platform in ["win32", "cygwin", "msys"]:
hotkey(["lcontrol", "a"])
hotkey_event = hotkey(["lcontrol", "a"])
hotkey(["lcontrol", "c"])
hotkey(["lcontrol", "v"])
hotkey(["lcontrol", "v"])
Expand Down
Loading