Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Checking any key
#1
So I'm making a game with my own animation system, and i'm using the keyboard module for key presses. I need to check if any key is pressed. No key in specific, like, I need to check if a key is being pressed. It's hard to explain. Basically, I'm wanting to make it play an animation if no keys are being pressed, and if any key is being pressed, it will check which one it is. Is there a function for this?
Quote
#2
you need a keyboard listener.
You can build your own with ctypes, or use one of the available packages: https://pypi.org/search/?q=keyboard
If you choose keyboard package: https://pypi.org/project/keyboard/
see examples on README
pygame has built in event handler for this (I'm only slightly familiar with pygame as 99% of my code is not game related),
but see: https://code-knowledge.com/create-game-w...ard-input/
Quote
#3
 

for event in pygame.event.get():
    if event.type == pygame.KEYDOWN:
        run_your_animation() ## whatever you want the key to trigger
        


Quote
#4
(Aug-01-2020, 09:14 AM)michael1789 Wrote:
 

for event in pygame.event.get():
    if event.type == pygame.KEYDOWN:
        run_your_animation() ## whatever you want the key to trigger
        



I'm not using pygame. I'm using TKinter Canvas and the keyboard module.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)