Browse Source

Merge pull request #7 from bordaigorl/fix-events

Fix too many PRESS events issue
master
Evan Widloski 6 years ago committed by GitHub
parent
commit
b46c1cc075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      remarkable_mouse/remarkable_mouse.py

16
remarkable_mouse/remarkable_mouse.py

@ -35,6 +35,10 @@ mouse = Controller()
logging.basicConfig(format='%(message)s') logging.basicConfig(format='%(message)s')
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# mouse state
LIFTED = 0
PRESSED = 1
# remap wacom coordinates in various orientations # remap wacom coordinates in various orientations
def fit(x, y, stylus_width, stylus_height, monitor, orientation): def fit(x, y, stylus_width, stylus_height, monitor, orientation):
@ -101,6 +105,7 @@ def open_eventfile(args, file='/dev/input/event0'):
def read_tablet(args): def read_tablet(args):
"""Loop forever and map evdev events to mouse""" """Loop forever and map evdev events to mouse"""
state = LIFTED
new_x = new_y = False new_x = new_y = False
monitor = get_monitors()[args.monitor] monitor = get_monitors()[args.monitor]
@ -129,9 +134,16 @@ def read_tablet(args):
if e_code == e_code_stylus_pressure: if e_code == e_code_stylus_pressure:
log.debug('\t\t{}'.format(e_value)) log.debug('\t\t{}'.format(e_value))
if e_value > args.threshold: if e_value > args.threshold:
mouse.press(Button.left) if state == LIFTED:
log.info('PRESS')
state = PRESSED
mouse.press(Button.left)
else: else:
mouse.release(Button.left) if state == PRESSED:
log.info('RELEASE')
state = LIFTED
mouse.release(Button.left)
# only move when x and y are updated for smoother mouse # only move when x and y are updated for smoother mouse
if new_x and new_y: if new_x and new_y:

Loading…
Cancel
Save