PsychoPy Coder -> Demos -> input -> 마우스에서는 다양한 종류의 마우스 입력에 반응하는 방법에 대한 데모 스크립트가 표시됩니다. 또한 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() 함수의 작동 메커니즘을 이해하는 데 도움이되었습니다. 그러나 필자는 getWheelRel() 함수를 지원하지 않는 "파이 게임 (pygame)"유형의 윈도우를 사용하고 있다는 것을 알아야했습니다. [0,0]을 반환합니다. mouse.getPressed를 사용하여 왼쪽 및 오른쪽 마우스 버튼을 눌러 위아래로 커서를 이동했습니다. – fishermen1275