Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

check key pressed pygame

import pygame
events = pygame.event.get()
for event in events:
    if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_LEFT:
            location -= 1
        if event.key == pygame.K_RIGHT:
            location += 1
Comment

pygame keys pressed

keys = pygame.key.get_pressed()
if keys[K_LEFT]:
    print("left")
Comment

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

how to detect when a key is pressed in pygame

import pygame

keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
    x -= 1
if keys[pygame.K_RIGHT]:
	x += 1
Comment

PREVIOUS NEXT
Code Example
Python :: find all color in image python 
Python :: Adding function to a varieble in python 
Python :: django login view 
Python :: python how to draw a square 
Python :: pandas index to datetime 
Python :: types of system 
Python :: remove element from list 
Python :: sort columns dataframe 
Python :: cryptography python 
Python :: how to display printed values without scientific notation python 
Python :: know datatype of pandas 
Python :: scaling data 
Python :: how to find a word in list python 
Python :: pandas read csv skip rows 
Python :: matplotlib point labels 
Python :: sys.path.append python 
Python :: feature importance naive bayes python 
Python :: pandas df filter by time hour 
Python :: checkbutton tkinter example 
Python :: convert ndarray to csr_matrix 
Python :: python get first character of string 
Python :: panda search strings in column 
Python :: pandas column filter 
Python :: uninstall python linux 
Python :: tkinter simple notification 
Python :: find percentage of missing values in a column in python 
Python :: get required packages from python project 
Python :: python while loop 
Python :: python substring in string 
Python :: python create directory if non existent 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =