“Se a barra de espaço pressionada Pygame” Respostas de código

Verifique a tecla Pygame pressionada

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

tecla pygame pressionada uma 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

Se a barra de espaço pressionada Pygame

import pygame

display = pygame.display.set_mode((500,500))

run = True

while run:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                print('Space bar is pressed')
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_SPACE:
                print('Space bar is released')
               
pygame.quit()
EXD KAVINxSBT

Respostas semelhantes a “Se a barra de espaço pressionada Pygame”

Perguntas semelhantes a “Se a barra de espaço pressionada Pygame”

Mais respostas relacionadas para “Se a barra de espaço pressionada Pygame” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código