Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pygame key pressed once

# Outside loop
pressed = False

# Inside loop
if event.type == pygame.KEYDOWN:
	if event.key == pygame.K_a and not pressed: #K_a can be replaced by any key
		# Do something
		pressed = True
	elif event.key != pygame.K_a:
    	pressed = False
Comment

pygame keys keep pressing

while not done:
    for e in event.get():
        if e.type == KEYDOWN:
            keys = key.get_pressed()
            if e.type == QUIT or keys[K_ESCAPE]:
                done = True
            if keys[K_DOWN]:
                print "DOWN"
Comment

pygame keys keep pressing

while not done:
    for e in event.get():
        if e.type == KEYDOWN:
            keys = key.get_pressed()
            if e.type == QUIT or keys[K_ESCAPE]:
                done = True
            while keys[K_DOWN]:
                print "DOWN"
                event.get()
                keys = key.get_pressed()
Comment

PREVIOUS NEXT
Code Example
Python :: check if a file exists in python 
Python :: how to use prettytable in python 
Python :: python how to import a module given a stringg 
Python :: arrays in python 
Python :: Change one value based on another value in pandas 
Python :: create tuples python 
Python :: faker, generates fake data for you 
Python :: Add two numbers as a linked list 
Python :: numpy make 2d array 1d 
Python :: python portfolio projects 
Python :: abstarct class python 
Python :: bubblesort python 
Python :: python template strings 
Python :: adding two strings together in python 
Python :: gevent with flask 
Python :: import library to stop warnings in jupyter 
Python :: how to link button to the urls in django 
Python :: convert df.isnull().sum() to dataframe 
Python :: python = align 
Python :: dict to tuple 
Python :: Math Module degrees() Function in python 
Python :: python plot speichern 
Python :: django 
Python :: python for loop 
Python :: check if digit or alphabet 
Python :: pandas disply options 
Python :: read data from gooogle cloud storage 
Python :: telegram.ext package python 
Python :: Django Rest Retrieve API View with Slug 
Python :: python var power of 2 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =