本文介紹了如何區(qū)分pygame中的鼠標(biāo)左鍵、右鍵單擊?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
來(lái)自pygame的api,它有:
From api of pygame, it has:
event type.MOUSEBUTTONDOWN, MOUSEBUTTONUP, MOUSEMOTION
但是沒(méi)有辦法區(qū)分左右點(diǎn)擊?
But there is no way to distinguish between right, left clicks?
推薦答案
點(diǎn)擊事件
if event.type == pygame.MOUSEBUTTONDOWN:
print(event.button)
event.button
可以等于多個(gè)整數(shù)值:
event.button
can equal several integer values:
1 - left click
2 - middle click
3 - right click
4 - scroll up
5 - scroll down
獲取鼠標(biāo)狀態(tài)
您也可以獲取當(dāng)前按鈕狀態(tài),而不是等待事件:
Fetching mouse state
Instead of waiting for an event, you can get the current button state as well:
state = pygame.mouse.get_pressed()
這會(huì)返回一個(gè)元組,格式為:(leftclick, middleclick, rightclick)
This returns a tuple in the form: (leftclick, middleclick, rightclick)
每個(gè)值都是一個(gè)布爾整數(shù),表示該按鈕是否被按下.
Each value is a boolean integer representing whether that button is pressed.
這篇關(guān)于如何區(qū)分pygame中的鼠標(biāo)左鍵、右鍵單擊?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!