Skip to content

Instantly share code, notes, and snippets.

@leander-dsouza
Last active June 16, 2023 07:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Flying Flappy Bird with arrow keys
"""fly() and dip() functions are called whenever the up arrow key is pressed or released respectively."""
def key_press(self, key):
"""Listen for key press."""
if key == Key.up:
self.fly()
return False
def key_release(self, _):
"""Listen for key release."""
self.dip()
return False
def keyboard_update(self, _):
"""ROS Timer Callback Keyboard Listener for a press and release."""
with keyboard.Listener(on_press=self.key_press) as listener_for_key_press:
listener_for_key_press.join()
with keyboard.Listener(on_release=self.key_release) as listener_for_key_release:
listener_for_key_release.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment