def socket_keystroke(message): try: keystroke = keystroke_request.parse_keystroke(message) except keystroke_request.Error as e: logger.error('Failed to parse keystroke request: %s', e) return hid_keycode = None processing_result = {'keystrokeId': keystroke.id, 'success': False} try: control_keys, hid_keycode = js_to_hid.convert(keystroke) except js_to_hid.UnrecognizedKeyCodeError: logger.warning('Unrecognized key: %s (keycode=%d)', keystroke.key, keystroke.key_code) socketio.emit('keystroke-received', processing_result) return if hid_keycode is None: logger.info('Ignoring %s key (keycode=%d)', keystroke.key, keystroke.key_code) socketio.emit('keystroke-received', processing_result) return try: fake_keyboard.send_keystroke(keyboard_path, control_keys, hid_keycode) except hid_write.WriteError as e: logger.error('Failed to write key: %s (keycode=%d). %s', keystroke.key, keystroke.key_code, e) socketio.emit('keystroke-received', processing_result) return processing_result['success'] = True socketio.emit('keystroke-received', processing_result)
def socket_keystroke(message): try: keystroke = keystroke_request.parse_keystroke(message) except keystroke_request.Error as e: logger.error('Failed to parse keystroke request: %s', e) return {'success': False} hid_keycode = None try: control_keys, hid_keycode = js_to_hid.convert(keystroke, keyboard_layout) except js_to_hid.UnrecognizedKeyCodeError: logger.warning('Unrecognized key: %s (keycode=%d)', keystroke.key, keystroke.key_code) return {'success': False} if hid_keycode is None: logger.info('Ignoring %s key (keycode=%d)', keystroke.key, keystroke.key_code) return {'success': False} try: fake_keyboard.send_keystroke(keyboard_path, control_keys, hid_keycode) except hid_write.WriteError as e: logger.error('Failed to write key: %s (keycode=%d). %s', keystroke.key, keystroke.key_code, e) return {'success': False} return {'success': True}
def socket_keystroke(message): logger.debug_sensitive('received keystroke message: %s', message) try: keystroke = keystroke_request.parse_keystroke(message) except keystroke_request.Error as e: logger.error_sensitive('Failed to parse keystroke request: %s', e) return {'success': False} hid_keycode = None try: control_keys, hid_keycode = js_to_hid.convert(keystroke) except js_to_hid.UnrecognizedKeyCodeError: logger.warning_sensitive('Unrecognized key: %s (keycode=%s)', keystroke.key, keystroke.code) return {'success': False} if hid_keycode is None: logger.info_sensitive('Ignoring %s key (keycode=%s)', keystroke.key, keystroke.code) return {'success': False} keyboard_path = flask.current_app.config.get('KEYBOARD_PATH') try: fake_keyboard.send_keystroke(keyboard_path, control_keys, hid_keycode) except hid_write.WriteError as e: logger.error_sensitive('Failed to write key: %s (keycode=%s). %s', keystroke.key, keystroke.code, e) return {'success': False} return {'success': True}
def key_stroke(hid_keycode, modifiers): try: fake_keyboard.send_keystroke(keyboard_path, modifiers, hid_keycode) except hid_write.WriteError as e: logger.error('Failed to write key: %s (keycode=%d). %s', hid_keycode, e) return {'success': False} return {'success': True}
def test_send_hid_keycode_to_hid_interface(self): with tempfile.NamedTemporaryFile() as input_file: keyboard.send_keystroke( keyboard_path=input_file.name, control_keys=keycodes.KEYCODE_NONE, hid_keycode=keycodes.KEYCODE_A, ) input_file.seek(0) # Press the key then release the key. self.assertEqual( b'\x00\x00\x04\x00\x00\x00\x00\x00' b'\x00\x00\x00\x00\x00\x00\x00\x00', input_file.read())
def test_send_control_key_to_hid_interface(self): with tempfile.NamedTemporaryFile() as input_file: keyboard.send_keystroke( keyboard_path=input_file.name, control_keys=keycodes.MODIFIER_LEFT_SHIFT, hid_keycode=keycodes.KEYCODE_NONE, ) input_file.seek(0) # Press the key, but do not release the key. This is to allow for # shift+click type behavior. self.assertEqual(b'\x02\x00\x00\x00\x00\x00\x00\x00', input_file.read())