diff --git a/.circleci/config.yml b/.circleci/config.yml
index ea520b4..4a0bce4 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -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
@@ -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:
diff --git a/.idea/Python_JEAutoControl.iml b/.idea/Python_JEAutoControl.iml
index 1311ac4..b494c46 100644
--- a/.idea/Python_JEAutoControl.iml
+++ b/.idea/Python_JEAutoControl.iml
@@ -5,7 +5,7 @@
-
+
diff --git a/.idea/discord.xml b/.idea/discord.xml
index a98cb47..cf77f1e 100644
--- a/.idea/discord.xml
+++ b/.idea/discord.xml
@@ -1,7 +1,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 55f032c..43bd6e9 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 586c452..b669725 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,8 +2,18 @@
+
-
+
+
+
+
+
+
+
+
+
+
@@ -29,15 +39,17 @@
-
-
-
+
+
+
-
+
+
+
-
+
@@ -52,11 +64,12 @@
-
-
+
+
+
@@ -69,8 +82,8 @@
-
-
+
+
@@ -78,12 +91,12 @@
-
+
-
+
@@ -92,7 +105,7 @@
-
+
@@ -105,7 +118,7 @@
-
+
@@ -114,7 +127,7 @@
-
+
@@ -122,12 +135,12 @@
-
+
-
+
@@ -136,7 +149,29 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -144,12 +179,12 @@
-
+
-
+
@@ -180,7 +215,7 @@
-
+
@@ -188,12 +223,12 @@
-
+
-
+
@@ -203,20 +238,21 @@
+
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
@@ -260,6 +296,12 @@
+
+
+
+
+
+
@@ -293,46 +335,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
\ No newline at end of file
diff --git a/circle_ci_test/timeout/timeout_test.py b/circle_ci_test/timeout/timeout_test.py
new file mode 100644
index 0000000..fa2d3b9
--- /dev/null
+++ b/circle_ci_test/timeout/timeout_test.py
@@ -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))
diff --git a/je_auto_control/__init__.py b/je_auto_control/__init__.py
index 6615e0e..914082e 100644
--- a/je_auto_control/__init__.py
+++ b/je_auto_control/__init__.py
@@ -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
diff --git a/je_auto_control/utils/je_auto_control_exception/exception_tag.py b/je_auto_control/utils/je_auto_control_exception/exception_tag.py
index 117a1e0..0053483 100644
--- a/je_auto_control/utils/je_auto_control_exception/exception_tag.py
+++ b/je_auto_control/utils/je_auto_control_exception/exception_tag.py
@@ -1,17 +1,12 @@
-"""
-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"
@@ -19,9 +14,7 @@
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"
@@ -29,38 +22,24 @@
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"
diff --git a/je_auto_control/utils/je_auto_control_exception/exceptions.py b/je_auto_control/utils/je_auto_control_exception/exceptions.py
index 6503c99..7db85b9 100644
--- a/je_auto_control/utils/je_auto_control_exception/exceptions.py
+++ b/je_auto_control/utils/je_auto_control_exception/exceptions.py
@@ -1,15 +1,9 @@
-"""
-general
-"""
-
-
+# general
class AutoControlException(Exception):
pass
-"""
-Keyboard
-"""
+# Keyboard
class AutoControlKeyboardException(AutoControlException):
@@ -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):
@@ -71,3 +55,8 @@ class AutoControlActionNullException(AutoControlException):
class AutoControlActionException(AutoControlException):
pass
+
+
+# timeout
+class AutoControlTimeoutException(AutoControlException):
+ pass
diff --git a/je_auto_control/utils/timeout/__init__.py b/je_auto_control/utils/timeout/__init__.py
new file mode 100644
index 0000000..bf34c58
--- /dev/null
+++ b/je_auto_control/utils/timeout/__init__.py
@@ -0,0 +1 @@
+from je_auto_control.utils.timeout import *
diff --git a/je_auto_control/utils/timeout/multiprocess_timeout.py b/je_auto_control/utils/timeout/multiprocess_timeout.py
new file mode 100644
index 0000000..a50b1bc
--- /dev/null
+++ b/je_auto_control/utils/timeout/multiprocess_timeout.py
@@ -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"
diff --git a/je_auto_control/wrapper/auto_control_keyboard.py b/je_auto_control/wrapper/auto_control_keyboard.py
index 206d4d0..e383c6b 100644
--- a/je_auto_control/wrapper/auto_control_keyboard.py
+++ b/je_auto_control/wrapper/auto_control_keyboard.py
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
diff --git a/je_auto_control/wrapper/auto_control_mouse.py b/je_auto_control/wrapper/auto_control_mouse.py
index 12bafde..e714dd6 100644
--- a/je_auto_control/wrapper/auto_control_mouse.py
+++ b/je_auto_control/wrapper/auto_control_mouse.py
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
diff --git a/je_auto_control/wrapper/auto_control_record.py b/je_auto_control/wrapper/auto_control_record.py
index 030f8ef..9925f7c 100644
--- a/je_auto_control/wrapper/auto_control_record.py
+++ b/je_auto_control/wrapper/auto_control_record.py
@@ -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():
@@ -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__":
diff --git a/setup.py b/setup.py
index 18f5994..9e077cf 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@
setuptools.setup(
name="je_auto_control",
- version="0.0.71",
+ version="0.0.73",
author="JE-Chen",
author_email="zenmailman@gmail.com",
description="auto testing",
diff --git a/test/platform_independent/test/keyboard/hotkey_test.py b/test/platform_independent/test/keyboard/hotkey_test.py
index 7a552b0..2f08a6b 100644
--- a/test/platform_independent/test/keyboard/hotkey_test.py
+++ b/test/platform_independent/test/keyboard/hotkey_test.py
@@ -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"])
diff --git a/test/platform_independent/test/keyboard/keyboard_is_press_test.py b/test/platform_independent/test/keyboard/keyboard_is_press_test.py
index 29758c3..48bdd5a 100644
--- a/test/platform_independent/test/keyboard/keyboard_is_press_test.py
+++ b/test/platform_independent/test/keyboard/keyboard_is_press_test.py
@@ -3,6 +3,7 @@
from je_auto_control import check_key_is_press
from je_auto_control import press_key
from je_auto_control import release_key
+from je_auto_control import AutoControlException
try:
"""
@@ -30,8 +31,8 @@
"""
if check_key_is_press(22):
sys.exit(0)
-except Exception:
- raise Exception
+except AutoControlException:
+ raise AutoControlException
finally:
if sys.platform in ["win32", "cygwin", "msys"]:
release_key("A")
diff --git a/test/platform_independent/test/keyboard/keyboard_type_test.py b/test/platform_independent/test/keyboard/keyboard_type_test.py
index c45b776..3b2c3e2 100644
--- a/test/platform_independent/test/keyboard/keyboard_type_test.py
+++ b/test/platform_independent/test/keyboard/keyboard_type_test.py
@@ -1,32 +1,11 @@
-import time
-
-from je_auto_control import type_key
from je_auto_control import keys_table
+from je_auto_control import type_key
"""
check keys
"""
print(keys_table.keys())
-"""
-Linux in every type and press then release need stop 0.01 time in my computer,i'm not sure it's right?
-
-example:
- type("T")
- time.sleep(0.01)
- type("E")
- time.sleep(0.01)
- type("S")
- time.sleep(0.01)
- type("T")
- time.sleep(0.01)
-
-or:
- press_key("T")
- release_key("T")
- time.sleep(0.01)
-"""
-
-type_key("T")
-type_key("E")
-type_key("S")
-type_key("T")
+assert (type_key("T") == "T")
+assert (type_key("E") == "E")
+assert (type_key("S") == "S")
+assert (type_key("T") == "T")
diff --git a/test/platform_independent/test/keyboard/keyboard_write_test.py b/test/platform_independent/test/keyboard/keyboard_write_test.py
index 62a23ef..ad16914 100644
--- a/test/platform_independent/test/keyboard/keyboard_write_test.py
+++ b/test/platform_independent/test/keyboard/keyboard_write_test.py
@@ -11,14 +11,14 @@
write("123456789")
press_key("return")
release_key("return")
-write("abcdefghijklmnopqrstuvwxyz")
+assert (write("abcdefghijklmnopqrstuvwxyz") == "abcdefghijklmnopqrstuvwxyz")
release_key("shift")
press_key("return")
release_key("return")
-write("abcdefghijklmnopqrstuvwxyz")
+assert (write("abcdefghijklmnopqrstuvwxyz") == "abcdefghijklmnopqrstuvwxyz")
press_key("return")
release_key("return")
"""
this write will print one error -> keyboard write error can't find key : Ѓ and write remain string
"""
-write("Ѓ123456789")
+assert (write("Ѓ123456789") == "123456789")
diff --git a/test/platform_independent/test/screen/screen_test.py b/test/platform_independent/test/screen/screen_test.py
index e7e856b..9210528 100644
--- a/test/platform_independent/test/screen/screen_test.py
+++ b/test/platform_independent/test/screen/screen_test.py
@@ -1,3 +1,4 @@
from je_auto_control import size
-
-print(size())
+screen_size = size()
+assert (size() is not None)
+print(screen_size)
\ No newline at end of file
diff --git a/test/platform_independent/test/screen/screenshot_test.py b/test/platform_independent/test/screen/screenshot_test.py
index 76b9453..ebe47a0 100644
--- a/test/platform_independent/test/screen/screenshot_test.py
+++ b/test/platform_independent/test/screen/screenshot_test.py
@@ -2,15 +2,15 @@
# choose screenshot region
image = screenshot(region=[300, 400, 500, 600])
-
+assert (image is not None)
print(image)
# screenshot and save
image = screenshot("test.png")
-
+assert (image is not None)
print(image)
# only screenshot
image = screenshot()
-
+assert (image is not None)
print(image)
diff --git a/test/platform_independent/test/timeout/timeout_test.py b/test/platform_independent/test/timeout/timeout_test.py
new file mode 100644
index 0000000..fa2d3b9
--- /dev/null
+++ b/test/platform_independent/test/timeout/timeout_test.py
@@ -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))
diff --git a/todo.je b/todo.je
deleted file mode 100644
index 6c32fe2..0000000
--- a/todo.je
+++ /dev/null
@@ -1,2 +0,0 @@
-check ide refactor
-refactor