def send_keystroke(keyboard_path, control_keys, hid_keycode): buf = [0] * 8 buf[0] = control_keys buf[2] = hid_keycode hid_write.write_to_hid_interface(keyboard_path, buf) # If it's not a modifier keycode, add a message indicating that the key # should be released after it is sent. if hid_keycode not in _MODIFIER_KEYCODES: release_keys(keyboard_path)
def send_keystroke(keyboard_path, control_keys, hid_keycode): buf = [0] * 8 buf[0] = control_keys buf[2] = hid_keycode hid_write.write_to_hid_interface(keyboard_path, buf) # If it's a normal keycode (i.e. not a standalone modifier key), add a # message indicating that the key should be released after it is sent. if hid_keycode: release_keys(keyboard_path)
def send_mouse_event(mouse_path, buttons, relative_x, relative_y): x, y = _scale_mouse_coordinates(relative_x, relative_y) buf = [0] * 5 buf[0] = buttons buf[1] = x & 0xff buf[2] = (x >> 8) & 0xff buf[3] = y & 0xff buf[4] = (y >> 8) & 0xff hid_write.write_to_hid_interface(mouse_path, buf)
def send_keystroke(keyboard_path, control_keys, hid_keycode): # First 8 bytes are for the first keystroke. Second 8 bytes are # all zeroes to indicate release of keys. buf = [0] * 8 buf[0] = control_keys buf[2] = hid_keycode hid_write.write_to_hid_interface(keyboard_path, buf) # If it's not a modifier keycode, add a message indicating that the key # should be released after it is sent. if hid_keycode not in _MODIFIER_KEYCODES: release_keys(keyboard_path)
def send_mouse_event(mouse_path, buttons, relative_x, relative_y, vertical_wheel_delta, horizontal_wheel_delta): x, y = _scale_mouse_coordinates(relative_x, relative_y) buf = [0] * 7 buf[0] = buttons buf[1] = x & 0xff buf[2] = (x >> 8) & 0xff buf[3] = y & 0xff buf[4] = (y >> 8) & 0xff buf[5] = vertical_wheel_delta & 0xff buf[6] = horizontal_wheel_delta & 0xff hid_write.write_to_hid_interface(mouse_path, buf)
def release_keys(keyboard_path): hid_write.write_to_hid_interface(keyboard_path, [0] * 8)