“Jika Space Bar menekan Pygame” Kode Jawaban

Periksa tombol Pygame yang ditekan

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

tombol pygame ditekan sekali

# 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

Jika Space Bar menekan 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

Jawaban yang mirip dengan “Jika Space Bar menekan Pygame”

Pertanyaan yang mirip dengan “Jika Space Bar menekan Pygame”

Lebih banyak jawaban terkait untuk “Jika Space Bar menekan Pygame” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya