add 2 finger scroll

master
Eggert Jung 5 years ago
parent c0ac58c806
commit 9dd06f80bb

@ -20,6 +20,7 @@ evcode_finger_xpos = 53
evcode_finger_ypos = 54 evcode_finger_ypos = 54
evcode_finger_pressure = 58 evcode_finger_pressure = 58
evcode_finger_mv_id = 0x39 evcode_finger_mv_id = 0x39
evcode_finger_mv_slot = 0x2f
# wacom digitizer dimensions # wacom digitizer dimensions
wacom_width = 15725 wacom_width = 15725
@ -139,34 +140,41 @@ def read_finger(args, remote_device):
t_mv_start = 0 t_mv_start = 0
mt_list = {}
mt_slot = 0
while True: while True:
_, _, e_type, e_code, e_value = struct.unpack('2IHHi', remote_device.read(16)) _, _, e_type, e_code, e_value = struct.unpack('2IHHi', remote_device.read(16))
if e_type == e_type_abs: if e_type == e_type_abs:
# handle x direction if e_code == evcode_finger_mv_slot:
if e_code == evcode_finger_xpos: mt_slot = e_value
log.debug(e_value)
if rel_orig_x == -1: if mt_slot == 0:
t_mv_last = t_mv_start # handle x direction
t_mv_start = time.time(); if e_code == evcode_finger_xpos:
if (t_mv_start - t_mv_last) < 0.3: log.debug(e_value)
mouse.press(Button.left)
rel_orig_x = e_value
x = e_value if rel_orig_x == -1:
new_x = True t_mv_last = t_mv_start
t_mv_start = time.time();
if (t_mv_start - t_mv_last) < 0.3:
mouse.press(Button.left)
rel_orig_x = e_value
# handle y direction x = e_value
if e_code == evcode_finger_ypos: new_x = True
log.debug('\t{}'.format(e_value))
if rel_orig_y == -1: # handle y direction
rel_orig_y = e_value if e_code == evcode_finger_ypos:
log.debug('\t{}'.format(e_value))
y = e_value if rel_orig_y == -1:
new_y = True rel_orig_y = e_value
y = e_value
new_y = True
if e_code == evcode_finger_mv_id: if e_code == evcode_finger_mv_id:
if e_value == -1: if e_value == -1:
@ -183,21 +191,36 @@ def read_finger(args, remote_device):
last_x = 0 last_x = 0
last_y = 0 last_y = 0
del mt_list[mt_slot]
else:
mt_list[mt_slot] = e_value
# 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:
if rel_orig_x != -1 and rel_orig_y != -1: if rel_orig_x != -1 and rel_orig_y != -1:
x_vect = y - rel_orig_y x_vect = rel_orig_x - x
y_vect = rel_orig_x - x y_vect = rel_orig_y - y
if(args.orientation == "bottom"): if(args.orientation == "bottom"):
mouse.move(old_x - x, old_y - y) arg_x = 2 * (x_vect - last_x)
arg_y = 2 * (y_vect - last_y)
if(args.orientation == "top"): if(args.orientation == "top"):
mouse.move(x - old_x, y - old_y) arg_x = 2 * (last_x - x_vect)
arg_y = 2 * (last_y - y_vect)
if(args.orientation == "left"): if(args.orientation == "left"):
mouse.move(2 * (x_vect - last_x), 2 * (y_vect - last_y)) arg_x = 2 * (last_y - y_vect)
arg_y = 2 * (x_vect - last_x)
if(args.orientation == "right"): if(args.orientation == "right"):
mouse.move(old_y - y, x - old_x) arg_x = 2 * (y_vect - last_y)
arg_y = 2 * (last_x - x_vect)
m_speed = 1
if len(mt_list) > 1:
mouse.scroll(0.2 * arg_x, 0.2 * arg_y)
else:
mouse.move(m_speed * arg_x, m_speed * arg_y)
new_x = new_y = False new_x = new_y = False

Loading…
Cancel
Save