The uinput library can emulate mouse and joystick events, as well as keyboard presses. To use the buttons to simulate a mouse, we can adjust the script to use mouse events (as well as defining mousemove to set the step size of the movement) using the following code:
MSG = ["M_UP","M_DOWN","M_LEFT","M_RIGHT","1","Enter"] events_mouse=(uinput.REL_Y,uinput.REL_Y, uinput.REL_X, uinput.REL_X,uinput.BTN_LEFT,uinput.BTN_RIGHT) mousemove=1
We also need to modify the button handling to provide continuous movement, as we don't need to keep track of the state of the keys for the mouse. To do so, use the following code:
#Perform the button presses/releases #(but only change state once) for idx, val in enumerate(btn_state): if MSG[idx] == "M_UP" or MSG[idx] == "M_LEFT": state = -mousemove else: state = mousemove if val == True: device.emit(events[idx], state) # Press. elif val == False: device.emit(events[idx], 0) # Release. time.sleep(0.01)