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_pressure = 58
evcode_finger_mv_id = 0x39
evcode_finger_mv_slot = 0x2f
# wacom digitizer dimensions
wacom_width = 15725
@ -139,34 +140,41 @@ def read_finger(args, remote_device):
t_mv_start = 0
mt_list = {}
mt_slot = 0
while True:
_, _, e_type, e_code, e_value = struct.unpack('2IHHi', remote_device.read(16))
if e_type == e_type_abs:
# handle x direction
if e_code == evcode_finger_xpos:
log.debug(e_value)
if e_code == evcode_finger_mv_slot:
mt_slot = e_value
if rel_orig_x == -1:
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
if mt_slot == 0:
# handle x direction
if e_code == evcode_finger_xpos:
log.debug(e_value)
x = e_value
new_x = True
if rel_orig_x == -1:
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
if e_code == evcode_finger_ypos:
log.debug('\t{}'.format(e_value))
x = e_value
new_x = True
if rel_orig_y == -1:
rel_orig_y = e_value
# handle y direction
if e_code == evcode_finger_ypos:
log.debug('\t{}'.format(e_value))
y = e_value
new_y = True
if rel_orig_y == -1:
rel_orig_y = e_value
y = e_value
new_y = True
if e_code == evcode_finger_mv_id:
if e_value == -1:
@ -183,21 +191,36 @@ def read_finger(args, remote_device):
last_x = 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
if new_x and new_y:
if rel_orig_x != -1 and rel_orig_y != -1:
x_vect = y - rel_orig_y
y_vect = rel_orig_x - x
x_vect = rel_orig_x - x
y_vect = rel_orig_y - y
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"):
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"):
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"):
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

Loading…
Cancel
Save