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.get_pressed()

if pygame.mouse.get_pressed()[0]:
	# do something when the left mouse button is pressed
keys = pygame.key.get_pressed()
if keys[pygame.K_a]:
	# do something when the a key is pressed
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

key pressed pygame

letters = {x: pygame.key.key_code(x) for x in "abcdefghijklmnopqrstuvwxyz"}

touche = pygame.key.get-pressed()

for (l, value) in letters.items() :
  if touche[value] :
    print(f"The letter {l} has been pressed ;)")
Comment

PREVIOUS NEXT
Code Example
Python :: plotly hide trace 
Python :: tkinter remove frame 
Python :: python enum declare 
Python :: remove minutes and seconds from datetime python 
Python :: python keyboard press 
Python :: change the color of the button on hovering tkinter 
Python :: python nmap 
Python :: python faker 
Python :: python remove duplicates from a list 
Python :: grassmann formula 
Python :: discordpy 
Python :: discord bot python meme command 
Python :: python not null 
Python :: pandas convert date column to year and month 
Python :: uninstall poetry 
Python :: multiple input in python 
Python :: django create model from dictionary 
Python :: save pythonpath 
Python :: savefig resolution 
Python :: pip show all installed packages 
Python :: car in programming python 
Python :: quit button tkinter 
Python :: how to make python remove the duplicates in list 
Python :: python des 
Python :: selenium scroll down python 
Python :: selenium how to handle element not found python 
Python :: import QMessageBox PyQt5 
Python :: python mock function return value 
Python :: pandas replace space with underscore in column names 
Python :: python colorama example 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =