Skip to content
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

Add a hotkey to pause listening to new movements #84

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions remarkable_mouse/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
import sys
from screeninfo import get_monitors, Monitor
from screeninfo import get_monitors, Monitor, Enumerator

from .codes import codes, types

Expand All @@ -28,7 +28,12 @@ def get_monitor(region, monitor_num, orientation):

# compute size of box encompassing all screens
max_x, max_y = 0, 0
for m in get_monitors():
if(sys.platform == 'darwin'):
log.debug(f"Handling MacOS monitors")
monitors = get_monitors(Enumerator.OSX)
else:
monitors = get_monitors()
for m in monitors:
x = m.x + m.width
y = m.y + m.height
max_x = max(x, max_x)
Expand All @@ -41,7 +46,7 @@ def get_monitor(region, monitor_num, orientation):
name="Fake monitor from region selection"
)
else:
monitor = get_monitors()[monitor_num]
monitor = monitors[monitor_num]

log.debug(f"Chose monitor: {monitor}")
log.debug(f"Screen size: ({max_x}, {max_y})")
Expand Down
18 changes: 11 additions & 7 deletions remarkable_mouse/evdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from itertools import cycle
from socket import timeout as TimeoutError
import libevdev
import keyboard

from .codes import codes, types
from .common import get_monitor, remap, wacom_max_x, wacom_max_y, log_event
Expand Down Expand Up @@ -76,7 +77,7 @@ def create_local_device():
return device.create_uinput_device()


def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode):
def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode,halt_hotkey):
"""Pipe rM evdev events to local device

Args:
Expand Down Expand Up @@ -139,10 +140,13 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
if codes[e_type][e_code] == 'ABS_Y':
e_value = int(mapped_y)

# pass events directly to libevdev
e_bit = libevdev.evbit(e_type, e_code)
e = libevdev.InputEvent(e_bit, value=e_value)
local_device.send_events([e])
if(not halt_hotkey or not keyboard.is_pressed(halt_hotkey)):
# pass events directly to libevdev
e_bit = libevdev.evbit(e_type, e_code)
e = libevdev.InputEvent(e_bit, value=e_value)
local_device.send_events([e])

if log.level == logging.DEBUG:
log_event(e_time, e_millis, e_type, e_code, e_value)
if log.level == logging.DEBUG:
log_event(e_time, e_millis, e_type, e_code, e_value)
else:
log.debug(f"listening of event stopped by hotkey")
34 changes: 19 additions & 15 deletions remarkable_mouse/pynput.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import struct
import keyboard
from screeninfo import get_monitors

# from .codes import EV_SYN, EV_ABS, ABS_X, ABS_Y, BTN_TOUCH
Expand All @@ -14,7 +15,7 @@
# finger_width = 767
# finger_height = 1023

def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode):
def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode, halt_hotkey):
"""Loop forever and map evdev events to mouse

Args:
Expand Down Expand Up @@ -60,17 +61,20 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
else:
mouse.release(Button.left)

if codes[e_type][e_code] == 'SYN_REPORT':
mapped_x, mapped_y = remap(
x, y,
wacom_max_x, wacom_max_y,
monitor.width, monitor.height,
mode, orientation,
)
mouse.move(
monitor.x + mapped_x - mouse.position[0],
monitor.y + mapped_y - mouse.position[1]
)

if log.level == logging.DEBUG:
log_event(e_time, e_millis, e_type, e_code, e_value)
if(not halt_hotkey or not keyboard.is_pressed(halt_hotkey)):
if codes[e_type][e_code] == 'SYN_REPORT':
mapped_x, mapped_y = remap(
x, y,
wacom_max_x, wacom_max_y,
monitor.width, monitor.height,
mode, orientation,
)
mouse.move(
monitor.x + mapped_x - mouse.position[0],
monitor.y + mapped_y - mouse.position[1]
)

if log.level == logging.DEBUG:
log_event(e_time, e_millis, e_type, e_code, e_value)
else:
log.debug(f"listening of event stopped by hotkey")
2 changes: 2 additions & 0 deletions remarkable_mouse/remarkable_mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def main():
parser.add_argument('--region', action='store_true', default=False, help="Use a GUI to position the output area. Overrides --monitor")
parser.add_argument('--threshold', metavar='THRESH', default=600, type=int, help="stylus pressure threshold (default 600)")
parser.add_argument('--evdev', action='store_true', default=False, help="use evdev to support pen pressure (requires root, Linux only)")
parser.add_argument('--hotkey', default='', type=str, help="define shortcut to halt the listening of clicks. \nFor combinations, use format 'shift+s, space'\ndefault: 'F2'")

args = parser.parse_args()

Expand Down Expand Up @@ -174,6 +175,7 @@ def main():
region=args.region,
threshold=args.threshold,
mode=args.mode,
halt_hotkey=args.hotkey
)

except PermissionError:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
'paramiko',
'libevdev',
'pynput',
'screeninfo'
'screeninfo',
'keyboard'
],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down