pygame官網上有說
The event queue gets pygame.KEYDOWN and pygame.KEYUP events when the keyboard buttons are pressed and released.
KEYDOWN = 按鍵按下
KEYUP = 按鍵釋放
以下代碼你可以拿去測試看看你滑鼠與鍵盤操作時會打印出甚麼消息import pygame
import sys
#初始化Pygame
pygame.init()
size = width, height = 800, 600 #寬, 高 (tuple)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("FishC Demo")
bg = (0, 0, 0)
#(字體, 大小)
font = pygame.font.Font(None, 20)
position = 0
line_height = font.get_linesize()
screen.fill(bg)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#(文本, 是否消除鋸齒, 顏色)
screen.blit(font.render(str(event), True, (0, 255, 0)), (0, position))
position += line_height
if position > height:
position = 0
screen.fill(bg)
pygame.display.flip()
若沒問題 檢查一下if語句的縮進有沒有正確 |