在PsychoPy編碼器 - >演示 - >輸入 - >鼠標,你會看到一個演示腳本如何對不同類型的鼠標輸入作出反應。另請參閱documentation。在代碼中,你會做這樣的事情,其中points
是你的線上的座標列表。
# Your points
points = [[0, 0], [1, 0.5], [2, 1], [3, 1.5]]
# Set up mouse
from psychopy import visual, event
win = visual.Window() # A mouse must be in a window
mouse = event.Mouse() # initialize mouse object
# Begin listening
event.clearEvents('mouse') # Do this in the beginning of every trial, to discard "old" mouse events.
index = 1 # start value
while not any(mouse.getPressed()): # for this example, keep running until any mouse button is pressed
#print mouse.getWheelRel()
scroll_change = int(mouse.getWheelRel()[1]) # returns (x,y) but y is what we understand as scroll.
if scroll_change != 0:
index += scroll_change # increment/decrement index
index = min(len(points)-1, max(index, 0)) # Round down/up to 0 or number of points
print points[index] # print it to show that it works. You would probably do something else here, once you have the coordinates.
你好,喬納斯,謝謝你的回答。它幫助我理解getWheelRel()函數的工作機制。然而,我不得不意識到我使用的是「pygame」類型的窗口,它顯然不支持getWheelRel()函數,因爲它繼續返回[0,0]。我通過用鼠標左鍵和右鍵鼠標按鈕來上下移動光標。 – fishermen1275