Advertisement
Zuma32

Panda3D key hold

Sep 12th, 2023 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. from direct.showbase.ShowBase import ShowBase
  2. from direct.task import Task
  3.  
  4. class Game(ShowBase):
  5.  
  6. def __init__(self):
  7. super().__init__()
  8.  
  9. self.keys = {
  10. "a": False,
  11. }
  12.  
  13. self.accept("a", self.key_down, ["a"])
  14. self.accept("a-up", self.key_up, ["a"])
  15.  
  16. taskMgr.add(self.check_key_state, "check_key_state")
  17.  
  18. def key_down(self, key):
  19. self.keys[key] = True
  20.  
  21. def key_up(self, key):
  22. self.keys[key] = False
  23.  
  24. def check_key_state(self, task):
  25. if self.keys["a"]:
  26. print("Key 'a' is held down")
  27. else:
  28. print("Key 'a' is not held down")
  29. return Task.cont
  30.  
  31. game = Game()
  32. game.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement