moving the cursor with the gamepad

pull/14/head
sezanzeb 4 years ago
parent f6869d7cd2
commit ba0a97dbdf

@ -38,7 +38,8 @@ For a list of supported keystrokes and their names, check the output of
- Alphanumeric `a` to `z` and `0` to `9`
- Modifiers `Alt_L` `Control_L` `Control_R` `Shift_L` `Shift_R`
If you can't find what you need, consult [linux/input-event-codes.h](https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h)
If you can't find what you need, consult
[linux/input-event-codes.h](https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h)
- Mouse buttons `BTN_LEFT` `BTN_RIGHT` `BTN_MIDDLE` `BTN_SIDE`
- Macro special keys `KEY_MACRO1` `KEY_MACRO2` ...

@ -60,12 +60,13 @@ if __name__ == '__main__':
window = Window()
def stop_injecting():
def stop():
if isinstance(window.dbus, Daemon):
# it created its own temporary daemon inside the process
# because none was running
window.dbus.stop()
window.on_close()
atexit.register(stop_injecting)
atexit.register(stop)
Gtk.main()

@ -293,23 +293,68 @@ class KeycodeInjector:
keymapper_device.device.path, keymapper_device.fd
)
newest_abs_event = None
abs_x = None
abs_y = None
# events only take ints, so a movement of 0.3 needs to add up to
# 1.2 to affect the cursor.
pending_x_rel = 0
pending_y_rel = 0
async def spam_mouse_movements():
while True:
# TODO get absinfo beforehand
max_value = 32767
if abs_y is not None and abs_x is not None:
speed = (abs_x ** 2 + abs_y ** 2) ** 0.5
max_speed = ((max_value ** 2) * 2) ** 0.5
non_linearity = 2
factor = (speed / max_speed) ** non_linearity
rel_x = abs_x / max_value * factor * 40
rel_y = abs_y / max_value * factor * 40
pending_x_rel = rel_x
pending_y_rel = rel_y
rel_x = int(pending_x_rel)
rel_y = int(pending_y_rel)
pending_x_rel -= rel_x
pending_y_rel -= rel_y
print('factor', factor)
print('speed', speed)
print(rel_x, rel_y)
self._write(
keymapper_device,
evdev.ecodes.EV_REL,
evdev.ecodes.ABS_Y,
rel_y
)
self._write(
keymapper_device,
evdev.ecodes.EV_REL,
evdev.ecodes.ABS_X,
rel_x
)
await asyncio.sleep(1 / 60)
asyncio.ensure_future(spam_mouse_movements())
async for event in device.async_read_loop():
if self.map_abs_to_rel() and event.type == evdev.ecodes.EV_ABS:
if event.code not in [evdev.ecodes.ABS_X, evdev.ecodes.ABS_Y]:
continue
# TODO somehow the injector has to keep injecting EV_REL
# codes with the most recent value to keep the mouse moving
# code 0:X, 1:Y
# TODO get absinfo beforehand
value = event.value // 2000
if value == 0:
continue
self._write(
keymapper_device,
evdev.ecodes.EV_REL,
event.code,
value
)
if event.code == evdev.ecodes.ABS_X:
abs_x = event.value
if event.code == evdev.ecodes.ABS_Y:
abs_y = event.value
continue
if event.type != evdev.ecodes.EV_KEY:

Loading…
Cancel
Save