def test_raises_exception_on_blank_code(self): with self.assertRaises(js_to_hid.UnrecognizedKeyCodeError): js_to_hid.convert( keystroke.Keystroke(left_meta_modifier=False, right_meta_modifier=False, left_alt_modifier=False, right_alt_modifier=False, left_shift_modifier=False, right_shift_modifier=False, left_ctrl_modifier=False, right_ctrl_modifier=False, key='a', code=''))
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 test_converts_simple_keystroke(self): modifier_bitmask, hid_keycode = convert( keystroke.Keystroke(left_meta_modifier=False, left_alt_modifier=False, left_shift_modifier=False, left_ctrl_modifier=False, right_alt_modifier=False, key='a', code='KeyA')) self.assertEqual(0, modifier_bitmask) self.assertEqual(hid.KEYCODE_A, hid_keycode)
def test_converts_right_ctrl_keystroke(self): modifier_bitmask, hid_keycode = convert( keystroke.Keystroke(left_meta_modifier=False, left_alt_modifier=False, left_shift_modifier=False, left_ctrl_modifier=True, right_alt_modifier=False, key='Control', code='ControlRight')) self.assertEqual(hid.MODIFIER_RIGHT_CTRL, modifier_bitmask) self.assertEqual(hid.KEYCODE_NONE, hid_keycode)
def test_converts_shifted_keystroke(self): modifier_bitmask, hid_keycode = convert( keystroke.Keystroke(left_meta_modifier=False, left_alt_modifier=False, left_shift_modifier=True, left_ctrl_modifier=False, right_alt_modifier=False, key='A', code='KeyA')) self.assertEqual(hid.MODIFIER_LEFT_SHIFT, modifier_bitmask) self.assertEqual(hid.KEYCODE_A, hid_keycode)
def test_converts_simple_azerty_keystroke(self): modifier_bitmask, hid_keycode = convert( keystroke.Keystroke(left_meta_modifier=False, left_alt_modifier=False, left_shift_modifier=False, left_ctrl_modifier=False, right_alt_modifier=False, key='a', key_code=65, is_right_modifier=False), 'azerty') self.assertEqual(0, modifier_bitmask) self.assertEqual(azerty.KEYCODE_A, hid_keycode)
def test_converts_right_ctrl_keystroke(self): modifier_bitmask, hid_keycode = convert( keystroke.Keystroke(left_meta_modifier=False, left_alt_modifier=False, left_shift_modifier=False, left_ctrl_modifier=True, right_alt_modifier=False, key='Control', key_code=17, is_right_modifier=True), 'qwerty') self.assertEqual(modifiers.RIGHT_CTRL, modifier_bitmask) self.assertEqual(qwerty.KEYCODE_RIGHT_CTRL, hid_keycode)
def test_converts_shifted_keystroke(self): modifier_bitmask, hid_keycode = convert( keystroke.Keystroke(left_meta_modifier=False, left_alt_modifier=False, left_shift_modifier=True, left_ctrl_modifier=False, right_alt_modifier=False, key='A', key_code=65, is_right_modifier=False), 'qwerty') self.assertEqual(modifiers.LEFT_SHIFT, modifier_bitmask) self.assertEqual(qwerty.KEYCODE_A, hid_keycode)
def test_converts_left_ctrl_with_shift_left_keystroke(self): modifier_bitmask, hid_keycode = convert( keystroke.Keystroke(left_meta_modifier=False, left_alt_modifier=False, left_shift_modifier=True, left_ctrl_modifier=True, right_alt_modifier=False, key='Control', code='ControlLeft')) self.assertEqual(hid.MODIFIER_LEFT_CTRL | hid.MODIFIER_LEFT_SHIFT, modifier_bitmask) self.assertEqual(hid.KEYCODE_LEFT_CTRL, hid_keycode)
def test_converts_keystroke_with_all_modifiers_pressed(self): modifier_bitmask, hid_keycode = convert( keystroke.Keystroke(left_meta_modifier=True, left_alt_modifier=True, left_shift_modifier=True, left_ctrl_modifier=True, right_alt_modifier=True, key='A', key_code=65, is_right_modifier=False), 'qwerty') self.assertEqual( modifiers.LEFT_META | modifiers.LEFT_ALT | modifiers.LEFT_SHIFT | modifiers.LEFT_CTRL | modifiers.RIGHT_ALT, modifier_bitmask) self.assertEqual(qwerty.KEYCODE_A, hid_keycode)
def test_converts_keystroke_with_all_modifiers_pressed(self): modifier_bitmask, hid_keycode = convert( keystroke.Keystroke(left_meta_modifier=True, left_alt_modifier=True, left_shift_modifier=True, left_ctrl_modifier=True, right_alt_modifier=True, key='A', code='KeyA')) self.assertEqual( hid.MODIFIER_LEFT_META | hid.MODIFIER_LEFT_ALT | hid.MODIFIER_LEFT_SHIFT | hid.MODIFIER_LEFT_CTRL | hid.MODIFIER_RIGHT_ALT, modifier_bitmask) self.assertEqual(hid.KEYCODE_A, hid_keycode)
def socket_keystroke(message): key_event = _parse_key_event(message) hid_keycode = None success = False try: control_keys, hid_keycode = js_to_hid.convert(key_event) except js_to_hid.UnrecognizedKeyCodeError: logger.warning('Unrecognized key: %s (keycode=%d)', key_event.key, key_event.key_code) if hid_keycode is None: logger.info('Ignoring %s key (keycode=%d)', key_event.key, key_event.key_code) else: hid.send(hid_path, control_keys, hid_keycode) success = True socketio.emit('keystroke-received', {'success': success})
def socket_keystroke(message): key_event = _parse_key_event(message) hid_keycode = None try: control_keys, hid_keycode = js_to_hid.convert(key_event) except js_to_hid.UnrecognizedKeyCodeError: logger.warning('Unrecognized key: %s (keycode=%d)', key_event.key, key_event.key_code) socketio.emit('keystroke-received', {'success': False}) return if hid_keycode is None: logger.info('Ignoring %s key (keycode=%d)', key_event.key, key_event.key_code) socketio.emit('keystroke-received', {'success': False}) return try: hid.send(hid_path, control_keys, hid_keycode) except hid.WriteError as e: logger.error('Failed to write key: %s (keycode=%d). %s', key_event.key, key_event.key_code, e) socketio.emit('keystroke-received', {'success': False}) return socketio.emit('keystroke-received', {'success': True})