It iterates over the circles list and uses the contains function to check if the mouse is currently over the shape. The code below can be added at the begining of the main loop. We simply pass the mouse as an argument to this function, and PsychoPy will do all the calculations and return True if the mouse falls within the circle. contains() function of the circle that we want to check. But we can also do it in a much simpler way by calling the. We could calculate this manually by calling the mouse.getPos() function and then doing a little bit of math to figure out if this position falls within the circumference of each of the circles. A mouse hover event can be defined as the event where the position of the mouse is within the boundary of an object that we are interested in (in this case, a circle). Two circles Implementing mouse hover eventsĭetecting a hover event is actually not that difficult, so we'll start with that. from psychopy import visual, eventĬircle_1 = visual.Circle(win, radius = 50, pos = )Ĭircle_2 = visual.Circle(win, radius = 50, pos = )įigure 1. On each screen flip it also checks if a key has been pressed, which will cause the program to exit the loop and close the window. By placing the circles in a list, I can simply iterate over that list and write the code that needs to be performed only once.įor now, the main loop of the program only displays the circles. This is because we are going to repeat a lot of code for each of these circles. I have added these two circles to a list. The basic setup of our code will create two circles. In this post I will show how you can use that information to react to 'mouse hover' and 'mouse click' events. The PsychoPy event submodule allows you to get information about the mouse position and which buttons have been pressed. This can easily be done using the event.waitKeys() or event.getKeys() functions. Most computer based experiments require a participant to press a button.
0 Comments
Leave a Reply. |