“pygame.key.get_pressed ()” 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

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

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

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya