You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
840 B
32 lines
840 B
import sys
|
|
import pygame
|
|
|
|
pygame.init()
|
|
screen = pygame.display.set_mode((640, 480)) # 设置屏幕大小
|
|
pygame.display.set_caption('keyboard ctrl') # 设置窗口标题
|
|
screen.fill((0, 0, 0)) # 屏幕填充RGB颜色
|
|
|
|
while True:
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
sys.exit()
|
|
|
|
keys = pygame.key.get_pressed()
|
|
for i in range(26):
|
|
if keys[pygame.K_a + i]:
|
|
print(chr(pygame.K_a + i))
|
|
|
|
# 检测上下左右键 #
|
|
if keys[pygame.K_UP]:
|
|
print("Up arrow")
|
|
if keys[pygame.K_DOWN]:
|
|
print("Down arrow")
|
|
if keys[pygame.K_LEFT]:
|
|
print("Left arrow")
|
|
if keys[pygame.K_RIGHT]:
|
|
print("Right arrow")
|
|
|
|
# ESC to quit #
|
|
if keys[pygame.K_ESCAPE]:
|
|
pygame.quit()
|
|
sys.exit() |