Skip to content

Dev #33

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

Merged
merged 3 commits into from
May 24, 2022
Merged

Dev #33

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.

191 changes: 98 additions & 93 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="je_auto_control_dev",
version="0.0.18",
version="0.0.20",
author="JE-Chen",
author_email="zenmailman@gmail.com",
description="auto testing",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from Xlib import X


def press_key(keycode: int):
def press_key(keycode: int) -> None:
"""
:param keycode which keycode we want to press
"""
Expand All @@ -24,7 +24,7 @@ def press_key(keycode: int):
print(repr(error), file=sys.stderr)


def release_key(keycode: int):
def release_key(keycode: int) -> None:
"""
:param keycode which keycode we want to release
"""
Expand Down
28 changes: 11 additions & 17 deletions je_auto_control/linux_with_x11/listener/x11_linux_listener.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from queue import Queue

from je_auto_control.utils.exception.exceptions import AutoControlException
from je_auto_control.utils.exception.exception_tag import linux_import_error
Expand Down Expand Up @@ -38,7 +39,7 @@ def __init__(self, default_daemon: bool = True):
self.event_position = 0, 0

# two times because press and release
def check_is_press(self, keycode: int):
def check_is_press(self, keycode: int) -> bool:
"""
:param keycode we want to check
"""
Expand All @@ -48,7 +49,7 @@ def check_is_press(self, keycode: int):
else:
return False

def run(self, reply):
def run(self, reply) -> None:
"""
:param reply listener return data
get data
Expand All @@ -70,14 +71,14 @@ def run(self, reply):
except AutoControlException:
raise AutoControlException(listener_error)

def record(self, record_queue):
def record(self, record_queue)-> None:
"""
:param record_queue the queue test_record action
"""
self.record_flag = True
self.record_queue = record_queue

def stop_record(self):
def stop_record(self) -> Queue:
self.record_flag = False
return self.record_queue

Expand All @@ -103,7 +104,7 @@ def check_is_press(self, keycode: int):
"""
return self.handler.check_is_press(keycode)

def run(self):
def run(self) -> None:
"""
while still listener
get context
Expand Down Expand Up @@ -139,41 +140,34 @@ def run(self):
self.handler.still_listener = False
self.still_listener = False

def record(self, record_queue):
def record(self, record_queue) -> None:
self.handler.record(record_queue)

def stop_record(self):
def stop_record(self) -> Queue:
return self.handler.stop_record()


xwindows_listener = XWindowsKeypressListener()
xwindows_listener.start()


def check_key_is_press(keycode: int):
def check_key_is_press(keycode: int) -> int:
"""
:param keycode check this keycode is press?
"""
return xwindows_listener.check_is_press(keycode)


def x11_linux_record(record_queue):
def x11_linux_record(record_queue) -> None:
"""
:param record_queue the queue test_record action
"""
xwindows_listener.record(record_queue)


def x11_linux_stop_record():
def x11_linux_stop_record() -> None:
"""
stop test_record action
"""
return xwindows_listener.stop_record()


if __name__ == "__main__":
from queue import Queue
test_queue = Queue()
xwindows_listener.record(test_queue)
while True:
pass
13 changes: 7 additions & 6 deletions je_auto_control/linux_with_x11/mouse/x11_linux_mouse_control.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import time
from typing import Tuple

from je_auto_control.utils.exception.exceptions import AutoControlException
from je_auto_control.utils.exception.exception_tag import linux_import_error
Expand All @@ -21,15 +22,15 @@
x11_linux_scroll_direction_right = 7


def position():
def position() -> Tuple[int, int]:
"""
get mouse current position
"""
coord = display.screen().root.query_pointer()._data
return coord["root_x"], coord["root_y"]


def set_position(x: int, y: int):
def set_position(x: int, y: int) -> None:
"""
:param x we want to set mouse x position
:param y we want to set mouse y position
Expand All @@ -39,7 +40,7 @@ def set_position(x: int, y: int):
display.sync()


def press_mouse(mouse_keycode: int):
def press_mouse(mouse_keycode: int) -> None:
"""
:param mouse_keycode mouse keycode we want to press
"""
Expand All @@ -48,7 +49,7 @@ def press_mouse(mouse_keycode: int):
display.sync()


def release_mouse(mouse_keycode: int):
def release_mouse(mouse_keycode: int) -> None:
"""
:param mouse_keycode which mouse keycode we want to release
"""
Expand All @@ -57,7 +58,7 @@ def release_mouse(mouse_keycode: int):
display.sync()


def click_mouse(mouse_keycode: int, x=None, y=None):
def click_mouse(mouse_keycode: int, x=None, y=None) -> None:
"""
:param mouse_keycode which mouse keycode we want to click
:param x set mouse x position
Expand All @@ -69,7 +70,7 @@ def click_mouse(mouse_keycode: int, x=None, y=None):
release_mouse(mouse_keycode)


def scroll(scroll_value: int, scroll_direction: int):
def scroll(scroll_value: int, scroll_direction: int) -> None:
""""
:param scroll_value scroll unit
:param scroll_direction what direction you want to scroll
Expand Down
13 changes: 2 additions & 11 deletions je_auto_control/linux_with_x11/record/x11_linux_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def __init__(self):
self.record_queue = None
self.result_queue = None

def record(self):
def record(self) -> None:
"""
create a new queue and start test_record
"""
self.record_queue = Queue()
x11_linux_record(self.record_queue)

def stop_record(self):
def stop_record(self) -> None:
"""
stop test_record
make a format action queue
Expand All @@ -50,12 +50,3 @@ def stop_record(self):
x11_linux_recoder = X11LinuxRecorder()


if __name__ == "__main__":
x11_record = X11LinuxRecorder()
x11_record.record()
from time import sleep
sleep(10)
temp = x11_record.stop_record()
for action in temp.queue:
print(action)

3 changes: 2 additions & 1 deletion je_auto_control/linux_with_x11/screen/x11_linux_screen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from typing import Tuple

from je_auto_control.utils.exception.exceptions import AutoControlException
from je_auto_control.utils.exception.exception_tag import linux_import_error
Expand All @@ -9,7 +10,7 @@
from je_auto_control.linux_with_x11.core.utils.x11_linux_display import display


def size():
def size() -> Tuple[int, int]:
"""
get screen size
"""
Expand Down
9 changes: 4 additions & 5 deletions je_auto_control/osx/keyboard/osx_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
if sys.platform not in ["darwin"]:
raise AutoControlException(osx_import_error)

import time

import AppKit
import Quartz
Expand Down Expand Up @@ -41,7 +40,7 @@
}


def normal_key(keycode: int, is_shift: bool, is_down: bool):
def normal_key(keycode: int, is_shift: bool, is_down: bool) -> None:
"""
:param keycode which keycode we want to press or release
:param is_shift use shift key ?
Expand All @@ -67,7 +66,7 @@ def normal_key(keycode: int, is_shift: bool, is_down: bool):
print(repr(error), file=sys.stderr)


def special_key(keycode: int, is_shift: bool):
def special_key(keycode: int, is_shift: bool) -> None:
"""
:param keycode which keycode we want to press or release
:param is_shift use shift key ?
Expand All @@ -89,7 +88,7 @@ def special_key(keycode: int, is_shift: bool):
Quartz.CGEventPost(0, event)


def press_key(keycode: int, is_shift: bool):
def press_key(keycode: int, is_shift: bool) -> None:
"""
:param keycode which keycode we want to press
:param is_shift is shift press?
Expand All @@ -100,7 +99,7 @@ def press_key(keycode: int, is_shift: bool):
normal_key(keycode, is_shift, True)


def release_key(keycode: int, is_shift: bool):
def release_key(keycode: int, is_shift: bool) -> None:
"""
:param keycode which keycode we want to release
:param is_shift is shift press?
Expand Down
2 changes: 1 addition & 1 deletion je_auto_control/osx/keyboard/osx_keyboard_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Quartz


def check_key_is_press(keycode: int):
def check_key_is_press(keycode: int) -> bool:
"""
:param keycode which keycode we want to check
"""
Expand Down
14 changes: 5 additions & 9 deletions je_auto_control/osx/listener/osx_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


from Cocoa import *
import time
from Foundation import *
from PyObjCTools import AppHelper

Expand All @@ -27,35 +26,32 @@ def applicationDidFinishLaunching_(self, aNotification):
NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSEventMaskRightMouseDown, mouse_right_handler)


def mouse_left_handler(event):
def mouse_left_handler(event) -> None:
loc = NSEvent.mouseLocation()
record_queue.put(("mouse_left", loc.x, loc.y))


def mouse_right_handler(event):
def mouse_right_handler(event) -> None:
loc = NSEvent.mouseLocation()
record_queue.put(("mouse_right", loc.x, loc.y))


def keyboard_handler(event):
def keyboard_handler(event) -> None:
if int(event.keyCode()) == 98:
pass
else:
record_queue.put(("type_key", int(hex(event.keyCode()), 16)))
print(event)


def osx_record():
def osx_record() -> None:
record_queue = Queue()
delegate = AppDelegate.alloc().init()
app.setDelegate_(delegate)
AppHelper.runEventLoop()


def osx_stop_record():
def osx_stop_record() -> Queue:
return record_queue


if __name__ == "__main__":
osx_record()

Loading