Skip to content

Instantly share code, notes, and snippets.

@leander-dsouza
Last active June 16, 2023 07:22
Show Gist options
  • Save leander-dsouza/783f47711513501f86fa096f03c4e063 to your computer and use it in GitHub Desktop.
Save leander-dsouza/783f47711513501f86fa096f03c4e063 to your computer and use it in GitHub Desktop.
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