Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pygame key button

import pygame as pg

## Basically there are 3 ways to check keyboard inputs:
## 1. If key its BEING PRESSED:
keys = pg.key.get_pressed()
if keys[pg.K_UP] or keys[ord('w')]:
	pass #do something while UP or 'w' is being pressed
    
## 2. if key was PRESSED ONCE:
while True:
	for event in pg.event.get():
    	if event.type == pg.KEYDOWN:
        	if event.key == pg.K_RIGHT:
            	pass #do something when RIGHT is pressed
                
## 3. if key was RELEASED:
while True:
	for event in pg.event.get():
    	if event.type == pg.KEYUP
        	if event.key == pg.K_w:
            	pass #do something when 'w' is released
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pygame #key #button
ADD COMMENT
Topic
Name
6+6 =