“tombol pygame ditekan sekali” 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

Kunci pygame ditekan

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

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

bagaimana mendeteksi kapan tombol ditekan dalam pygame

import pygame

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

Tombol Pygame yang ditekan

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

tombol pygame terus menekan

while not done:
    for e in event.get():
        if e.type == KEYDOWN:
            keys = key.get_pressed()
            if e.type == QUIT or keys[K_ESCAPE]:
                done = True
            if keys[K_DOWN]:
                print "DOWN"
Ugly Unicorn

Jawaban yang mirip dengan “tombol pygame ditekan sekali”

Pertanyaan yang mirip dengan “tombol pygame ditekan sekali”

Lebih banyak jawaban terkait untuk “tombol pygame ditekan sekali” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya