get the position of several mouse clicks

197 views
Skip to first unread message

ConsueloS

unread,
Feb 18, 2013, 7:39:09 PM2/18/13
to psychopy-users
Hi,
Does anyone have idea of how to implement the following in the coder
( psychopy 1.75.01):

I have one rectangle in the left of the screen and one in the rigth.
In each trial subjects have to click over a rectangle to terminate
a sound:
In some trials
a) one click in the Left Rect will terminate the sound,
and in other trials
b) left Rect click followed by click on rigth Rect will be necessary
or
c) Left Rect click - followed by RigthRect click - and left Rect
click again.

So I basically need a way to test whether ( according to type of
trial : a), b) or c) ) the correct sequence of clicks in the
appropriate locations were made.
I been using Rect.contain() function to test whether the mouse and
click in within the rectangle, but of course gets complicated to test
trials b) and c) where a sequence of clicks in given locations is
needed.

I do not know how to specify my correct response when my trial is b)
and c)
I tried using LRL= [0,1,0] and RLR as [1,0,1]

Any advice on how to do this is greatly appreciated!!!!


if t >= 0.5 and mouse.status == NOT_STARTED:
mouse.tStart = t # underestimates by a little under one
frame
mouse.frameNStart = frameN # exact frame index
mouse.status = STARTED
event.mouseButtons = [0, 0, 0] # reset mouse buttons to
be 'up'
if mouse.status == STARTED: # only update if started and not
stopped!
buttons = mouse.getPressed()
if sum(buttons)>0 and LeftRect.contains(mouse.getPos()):
x, y = mouse.getPos()
mouse.x.append(x)
mouse.y.append(y)
mouse.leftButton.append(buttons[0])
mouse.midButton.append(buttons[1])
mouse.rightButton.append(buttons[2])
mouse.time.append(globalClock.getTime())
leftRect.append('1') #LeftRect an empty list,
will append 1 to the list if left rect is clicked
RigthRect.append('0')
if len(str(buttons[0]))==len(correctResp):
if leftRect==correctResp:
break
elif sum(buttons)>0 and
RigthRect.contains(mouse.getPos()):
x, y = mouse.getPos()
mouse.x.append(x)
mouse.y.append(y)
mouse.leftButton.append(buttons[0])
mouse.midButton.append(buttons[1])
mouse.rightButton.append(buttons[2])
mouse.time.append(globalClock.getTime())
leftRect.append('0')
RigthRect.append(''1)

if len(str(buttons[0]))==len(correctResp): # I only
will be using the left button of the mouse
if leftRect==correctResp:'
x=False
sound.stop()
LeftRect.setAutoDraw(False)
RigthRect.setAutoDraw(False)
mouse.status=FINISHED
elif RigthRect==correctResp:
x=False
sound.stop()
LeftRect.setAutoDraw(False)
RigthRect.setAutoDraw(False)
mouse.status=FINISHED


#if str(buttons[0])==correctResp:





Chris Cox

unread,
Feb 19, 2013, 10:47:37 AM2/19/13
to psychop...@googlegroups.com
Hi Consuelos,

So, I'll be up front and say I didn't look too deeply at your code---you might have been on to something. The fact that I solved it differently doesn't invalidate your efforts.

When dealing with mouse clicks, there is a complication because the sampling rate is really fast. So, a single behavioral "click" ends up returning a ton of .getPressed() events to the program.  One way to handle this is manually impose a sampling rate.  Don't treat another response as valid until some time has elapsed.  You could also code up a "gating" function, so that if getPressed()==True, the gate closes until getPressed() == False... but I didn't want to think that through right now.  Or I guess you could check for pairs of press events, and require that the first be False and the second True...

Anyway, you need to define a click.  That's probably the hardest part.

Then, if I understand correctly, you need to check for sequences of three "clicks" that follow a pattern.  You can do this by appending to a list, as it looks like you were thinking about.  What I did in the linked code was to wait until I collected n clicks, and then check to see if that matched the goal sequence.  If not, I deleted the first element of the list and collected another response (appended to the end). Then I check the new set of n, and I do that until the sequence is discovered.

I might have gone a little overboard with the "minimum working example", but the way I thought about the solution suggested that defining the experiment as a class would make things easier.  It's not absolutely necessary. Sometimes it makes things a little more intuitive.


HTH!
Chris








--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



ConsueloS

unread,
Feb 19, 2013, 3:54:31 PM2/19/13
to psychopy-users
Thanks Chris!
This is so helpful! didn't think about the sampling rate problem.
Thank you so much for the help!
Reply all
Reply to author
Forward
0 new messages