所以即時建立一個基於pi的機器人。 它使用ps3控制器進行輸入。當按下X按鈕時,它會拍攝照片。出於某種原因,一次只需要5次左右的拍攝。有沒有辦法反彈輸入,以便只識別一次按鍵?python pygame如何去除按鈕?
我假設它的註冊多個印刷機每次...部分代碼連接,但我必須說明大部分是從piborg.org使用
joystick = pygame.joystick.Joystick(0)
button_take_picture = 14 # X button
while running:
# Get the latest events from the system
hadEvent = False
events = pygame.event.get()
# Handle each event individually
for event in events:
if event.type == pygame.QUIT:
# User exit
running = False
elif event.type == pygame.JOYBUTTONDOWN:
# A button on the joystick just got pushed down
hadEvent = True
elif event.type == pygame.JOYAXISMOTION:
# A joystick has been moved
hadEvent = True
if hadEvent:
if joystick.get_button(button_take_picture):
take_picture()
你可以阻止一個以上的調用'take_picture()'直到你得到一個'JOYBUTTONUP' – Tomer
有意思,你能解釋更多嗎?即時通訊全新的pygame /使用按鈕和即時通訊相當新的python ...這是我的第一個大項目!你會簡單地'如果event.type == pygame.JOYBUTTONUP:'在'take_picture()'之前? – JONAS402
是的,只有釋放按鈕時,纔會拍照。 – Tomer