“teclas de pygame presionadas” Código de respuesta

Verifique la tecla Pygame presionada

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
TheProgrammer

teclas de pygame presionadas

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

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
Rocku0

tecla PyGame presionada una vez

# 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
Thankful Turkey

Cómo detectar cuándo se presiona una tecla en Pygame

import pygame

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

tecla presionó 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 ;)")
Selfish Stoat

Respuestas similares a “teclas de pygame presionadas”

Preguntas similares a “teclas de pygame presionadas”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código