Skip to content

add osx record #4

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 1 commit into from
Oct 12, 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
1 change: 1 addition & 0 deletions je_auto_control/osx/listener/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from je_auto_control.osx.listener import *
17 changes: 0 additions & 17 deletions je_auto_control/osx/listener/osx_keyboard_listener.py

This file was deleted.

63 changes: 63 additions & 0 deletions je_auto_control/osx/listener/osx_listener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import sys

if sys.platform not in ["darwin"]:
raise Exception("should be only loaded on MacOS")


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

from queue import Queue


class RecordQueue(object):

def __init__(self):
self.record_queue = None

def reset_queue(self):
self.record_queue = Queue()


record_queue_manager = RecordQueue()

class AppDelegate(NSObject):
def applicationDidFinishLaunching_(self, aNotification):
NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSEventMaskKeyDown, keyboard_handler)
NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSEventMaskLeftMouseDown, mouse_left_handler)
NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSEventMaskRightMouseDown, mouse_right_handler)


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


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


def keyboard_handler(event):
record_queue_manager.record_queue.put(("keyboard", int(hex(event.keyCode()), 16)))
if int(event.keyCode()) == 98:
AppHelper.stopEventLoop()


def osx_record():
record_queue_manager.reset_queue()
app = NSApplication.sharedApplication()
delegate = AppDelegate.alloc().init()
NSApp().setDelegate_(delegate)
AppHelper.runEventLoop()


def osx_stop_record():
return record_queue_manager.record_queue


if __name__ == "__main__":
osx_record()

20 changes: 0 additions & 20 deletions je_auto_control/osx/listener/osx_mouse_listener.py

This file was deleted.

1 change: 1 addition & 0 deletions je_auto_control/osx/record/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from je_auto_control.osx.record import *
26 changes: 26 additions & 0 deletions je_auto_control/osx/record/osx_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys

if sys.platform not in ["darwin"]:
raise Exception("should be only loaded on MacOS")


from je_auto_control.osx.listener.osx_listener import osx_record
from je_auto_control.osx.listener.osx_listener import osx_stop_record

from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlRecordException


class OSXRecorder(object):


def record(self):
osx_record()


def stop_record(self):
record_queue = osx_stop_record()
if record_queue is None:
raise AutoControlRecordException
return osx_stop_record()

osx_recorder = OSXRecorder()
7 changes: 6 additions & 1 deletion je_auto_control/wrapper/auto_control_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ def stop_record():
raise AutoControlRecordException(record_not_found_action_error)



if __name__ == "__main__":
record()
from time import sleep
sleep(10)
stop_record()
sleep(3)
import sys
if sys.platform in ["darwin"]:
record()
stop_record()


4 changes: 3 additions & 1 deletion je_auto_control/wrapper/platform_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
from je_auto_control.osx.screen import osx_screen
from je_auto_control.osx.keyboard import osx_keyboard
from je_auto_control.osx.keyboard import osx_keyboard_check
from je_auto_control.osx.record.osx_record import osx_recorder

elif sys.platform in ["linux", "linux2"]:
from je_auto_control.linux_with_x11.core.utils.x11_linux_vk import x11_linux_key_backspace
Expand Down Expand Up @@ -863,7 +864,8 @@
keyboard_check = osx_keyboard_check
mouse = osx_mouse
screen = osx_screen
if None in [keys_table, mouse_table, keyboard_check, keyboard, mouse, screen]:
recorder = osx_recorder
if None in [keys_table, mouse_table, keyboard_check, keyboard, mouse, screen, recorder]:
raise AutoControlException("Can't init auto control")

elif sys.platform in ["linux", "linux2"]:
Expand Down