I want to check if a key is pressed in pygame. I do not mean by using the KEYDOWN or KEYUP methods. The thing is, if I only check for those methods, I only get feedback (I don't know any other way to phrase it) AS the key is pressed. I do not get feedback in between key press and release. I want to get if the key is currently down.
            Asked
            
        
        
            Active
            
        
            Viewed 1,714 times
        
    2
            
            
        - 
                    1Does this answer your question? [How to use pygame.KEYDOWN?](https://stackoverflow.com/questions/25494726/how-to-use-pygame-keydown) – Ismael Padilla Jan 20 '20 at 20:59
- 
                    1You can assume that the key is being held down between the `keydown` and `keyup` events. – Ismael Padilla Jan 20 '20 at 20:59
1 Answers
2
            
            
        The current state of the keys can be get by pygame.key.get_pressed().
Get the sate of the keys keys = pygame.key.get_pressed() and evaluate if the UP or DOWN is pressed by if keys[pygame.K_UP]: respectively if keys[pygame.K_DOWN]:, continuously in the main application loop:
run = True
while run:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    keys = pygame.key.get_pressed()
    if keys[pygame.K_UP]:
        # [...]
    if keys[pygame.K_DOWN]:
        # [...]
Note, the states which are returned by pygame.key.get_pressed() are updated when the events are handled by pygame.event.pump() or pygame.event.get().
 
    
    
        Rabbid76
        
- 202,892
- 27
- 131
- 174
 
    