|
25 | 25 |
|
26 | 26 | event_dict = { |
27 | 27 | # mouse |
28 | | - "mouse_left": ("click_mouse", click_mouse), |
29 | | - "mouse_right": ("click_mouse", click_mouse), |
30 | | - "mouse_middle": ("click_mouse", click_mouse), |
31 | | - "mouse_table": ("mouse_table", mouse_table), |
32 | | - "position": ("position", position), |
33 | | - "press_mouse": ("press_mouse", press_mouse), |
34 | | - "release_mouse": ("release_mouse", release_mouse), |
35 | | - "scroll": ("scroll", scroll), |
36 | | - "set_position": ("set_position", set_position), |
37 | | - "special_table": ("special_table", special_table), |
| 28 | + "mouse_left": click_mouse, |
| 29 | + "mouse_right": click_mouse, |
| 30 | + "mouse_middle": click_mouse, |
| 31 | + "mouse_table": mouse_table, |
| 32 | + "position": position, |
| 33 | + "press_mouse": press_mouse, |
| 34 | + "release_mouse": release_mouse, |
| 35 | + "scroll": scroll, |
| 36 | + "set_position": set_position, |
| 37 | + "special_table": special_table, |
38 | 38 | # keyboard |
39 | | - "keys_table": ("keys_table", keys_table), |
40 | | - "type_key": ("type_key", type_key), |
41 | | - "press_key": ("press_key", press_key), |
42 | | - "release_key": ("release_key", release_key), |
43 | | - "check_key_is_press": ("check_key_is_press", check_key_is_press), |
44 | | - "write": ("write", write), |
45 | | - "hotkey": ("hotkey", hotkey), |
| 39 | + "keys_table": keys_table, |
| 40 | + "type_key": type_key, |
| 41 | + "press_key": press_key, |
| 42 | + "release_key": release_key, |
| 43 | + "check_key_is_press": check_key_is_press, |
| 44 | + "write": write, |
| 45 | + "hotkey": hotkey, |
46 | 46 | # image |
47 | | - "locate_all_image": ("locate_all_image", locate_all_image), |
48 | | - "locate_image_center": ("locate_image_center", locate_image_center), |
49 | | - "locate_and_click": ("locate_and_click", locate_and_click), |
| 47 | + "locate_all_image": locate_all_image, |
| 48 | + "locate_image_center": locate_image_center, |
| 49 | + "locate_and_click": locate_and_click, |
50 | 50 | # screen |
51 | | - "size": ("size", size), |
52 | | - "screenshot": ("screenshot", screenshot) |
| 51 | + "size": size, |
| 52 | + "screenshot": screenshot |
53 | 53 | } |
54 | 54 |
|
55 | 55 |
|
56 | 56 | def execute_event(action): |
57 | 57 | event = event_dict.get(action[0]) |
58 | | - if event[0] in ["click_mouse"]: |
59 | | - event[1](action[0], action[1], action[2]) |
60 | | - elif event[0] in ["type_key", "press_key", "release_key", "check_key_is_press", "write"]: |
61 | | - event[1](action[1]) |
62 | | - elif event[0] in ["position", "record", "stop_record", "size"]: |
63 | | - event[1]() |
64 | | - elif event[0] in ["set_position", "screenshot"]: |
65 | | - event[1](action[1], action[2]) |
66 | | - elif event[0] in ["locate_all_image", "locate_image_center", "press_mouse", "release_mouse"]: |
67 | | - event[1](action[1], action[2], action[3]) |
68 | | - elif event[0] in ["scroll", "locate_and_click"]: |
69 | | - event[1](action[1], action[2], action[3], action[4]) |
| 58 | + if len(action) == 2: |
| 59 | + event(**action[1]) |
| 60 | + else: |
| 61 | + event() |
70 | 62 |
|
71 | 63 |
|
72 | 64 | def execute_action(action_list: list): |
@@ -94,27 +86,27 @@ def execute_action(action_list: list): |
94 | 86 | test_list = None |
95 | 87 | if sys.platform in ["win32", "cygwin", "msys"]: |
96 | 88 | test_list = [ |
97 | | - ("type_key", 65), |
98 | | - ("mouse_left", 500, 500), |
99 | | - ("position", "position"), |
100 | | - ("press_mouse", "mouse_left", 500, 500), |
101 | | - ("release_mouse", "mouse_left", 500, 500), |
| 89 | + ["type_key", {"keycode": 65}], |
| 90 | + ["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}], |
| 91 | + ["position"], |
| 92 | + ["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}], |
| 93 | + ["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}], |
102 | 94 | ] |
103 | 95 | elif sys.platform in ["linux", "linux2"]: |
104 | 96 | test_list = [ |
105 | | - ("type_key", 38), |
106 | | - ("mouse_left", 500, 500), |
107 | | - ("position", "position"), |
108 | | - ("press_mouse", "mouse_left", 500, 500), |
109 | | - ("release_mouse", "mouse_left", 500, 500) |
| 97 | + ["type_key", {"keycode": 38}], |
| 98 | + ["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}], |
| 99 | + ["position"], |
| 100 | + ["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}], |
| 101 | + ["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}], |
110 | 102 | ] |
111 | 103 | elif sys.platform in ["darwin"]: |
112 | 104 | test_list = [ |
113 | | - ("type_key", 0x00), |
114 | | - ("mouse_left", 500, 500), |
115 | | - ("position", "position"), |
116 | | - ("press_mouse", "mouse_left", 500, 500), |
117 | | - ("release_mouse", "mouse_left", 500, 500) |
| 105 | + ["type_key", {"keycode": 0x00}], |
| 106 | + ["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}], |
| 107 | + ["position"], |
| 108 | + ["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}], |
| 109 | + ["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}], |
118 | 110 | ] |
119 | 111 | print("\n\n") |
120 | 112 | print(execute_action(test_list)) |
0 commit comments