Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_controller_events(self):
"""Tests that events sent by a controller are received correctly"""
with self.assert_event(
'Failed to send press',
on_press=lambda k: getattr(k, 'char', None) == u'a'):
self.controller.press(u'a')
with self.assert_event(
'Failed to send release',
on_release=lambda k: getattr(k, 'char', None) == u'a'):
self.controller.release(u'a')
self.controller.press(pynput.keyboard.Key.enter)
self.controller.release(pynput.keyboard.Key.enter)
input()
def simulateCopy(self):
with self.keyboard.pressed(Key.ctrl):
self.keyboard.press('c')
self.keyboard.release('c')
def _on_release(self, key):
if key == keyboard.Key.up or key == keyboard.Key.down:
self.throttle.value = 0.0
elif key == keyboard.Key.left or key == keyboard.Key.right:
self.steering.value = 0.0
def on_release(key):
if key == Key.esc:
# Stop listener
return False
elif key == Key.caps_lock:
self.send = not self.send
if self.send and key != Key.caps_lock:
self.sendKey(key, Host.KEY_RELEASE)
def on_press(self, key):
#keyboard.type('test')
if key == keyboard.Key.up:
keyboard.type('UP\n')
self._cmdHistoryIndex -= 1
elif key == keyboard.Key.down:
keyboard.type('DOWN\n')
self._cmdHistoryIndex += 1
if self._cmdHistoryIndex < 0:
self._cmdHistoryIndex == 0;
elif self._cmdHistoryIndex > (len(self._cmdHistory) - 1):
self._cmdHistoryIndex = len(self._cmdHistory) - 1
return