Mouse with touchscreen

1,385 views
Skip to first unread message

Amy

unread,
Apr 10, 2013, 5:58:43 AM4/10/13
to psychop...@googlegroups.com
I have developed a task which is compatible with touchscreen.

Participants must choose between 4 stimuli displayed on the screen. This works fine with the mouse as long as you move the mouse off screen after each trial (wouldn't expect participants to have to do this!). the reason being is that the mouse stays in the same position and therefore skips through all trials just pressing that same stimuli. I can't have the mouse set to select on the click because it will be used on a touchscreen.

if mouse.getPressed() and bluesquare.contains(mouse):
  response="1"
  mouse.setPos([0,0]) #this doesn't work
  trials.finished=True

is there a work around? any ideas would be much appreciated!

Jonathan Peirce

unread,
Apr 10, 2013, 6:04:52 AM4/10/13
to psychop...@googlegroups.com
I *think* something like this would work (assuming that the touchscreen
does 'release' the mouse when the subjects finger comes off)::

if mouse.getPressed() and bluesquare.contains(mouse):
response="1"
mouse.setPos([0,0]) #this doesn't work
trials.finished=True

#wait unitl mouse is released
while mouse.getPressed():
pass #do nothing


On 10/04/2013 10:58, Amy wrote:
> if mouse.getPressed() and bluesquare.contains(mouse):
> response="1"
> mouse.setPos([0,0]) #this doesn't work
> trials.finished=True

--
Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

Amy Bland

unread,
Apr 10, 2013, 6:30:44 AM4/10/13
to psychop...@googlegroups.com
No that doesn't seem to work. Touchscreen releases the mouse button press. The only way I can think of to get around this is to have the participant touch something at feedback which is away from the stimulus locations for the trial itself.

when mouse.setPos() is up and running this issue should become redundant anyway.

Thank you Jon.




--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/psychopy-users/uJcJb73H630/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to psychopy-users+unsubscribe@googlegroups.com.
To post to this group, send email to psychopy-users@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Amy Bland

unread,
Apr 10, 2013, 6:31:20 AM4/10/13
to psychop...@googlegroups.com
*doesn't release button press

Jeremy Gray

unread,
Apr 10, 2013, 7:18:58 AM4/10/13
to psychop...@googlegroups.com
not sure I fully understand the mouse vs touch screen issues, but
would it work to do bluesquare.setPos() to move if offscreen (i.e.,
instead of mouse.setPos() ), and then move bluesquare back into
position later after the clicks or whatever have ended? you could even
have a copy of bluesquare (eg bluesquareCopy) that provides visual
continuity so the subject would not see anything. you would not check
for bluesquareCopy.contains(mouse).
>>> 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.
>>>
>>>
>>
>
> --
> 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.

Amy Bland

unread,
Apr 10, 2013, 7:35:07 AM4/10/13
to psychop...@googlegroups.com

thank you - like you suggest, the bluesquare.setPos() works to move off-screen (when i test using a mouse and a laptop). However, because I want to run as touch screen I can't use clicks - so as soon as it's back in position the mouse just continues to select the same stimulus. In fact the stimuli are even displayed, it just quickly skips to the end whilst the data shows that the same stimuli has been selected continuously.

Jeremy Gray

unread,
Apr 10, 2013, 7:52:07 AM4/10/13
to psychop...@googlegroups.com
so the issue with the touchscreen is that its like a mouse hovering,
not a mouse click? so if someone leaves their finger in place for a
long time (the way you leave a mouse in place, its always there on the
screen), the same stimulus will keep getting selected?

if this is the situation, one approach is to detect both when someone
first touches or clicks the blue square (or whatever), and also when
they release it. only let your program continue with the release
(i.e., lifting the finger or moving the mouse out of the shape
boundary, as I understand it).

if mouse.getPressed() and bluesquare.contains(mouse):
response="1"
mouse.setPos([0,0]) #this doesn't work
trials.finished=True

#wait until move out of the square
while bluesquare.contains(mouse):
pass #do nothing

Amy Bland

unread,
Apr 10, 2013, 9:44:35 AM4/10/13
to psychop...@googlegroups.com
yes, exactly - it's just like the mouse hovering over the stimuli.

I tried the above but I cannot select any of the stimuli and it causes PsychoPy to crash.

Jeremy Gray

unread,
Apr 10, 2013, 10:21:55 AM4/10/13
to psychop...@googlegroups.com
my intuitions about tablets are not much to go on, never tried
programming for one. and it sounds like things work differently. so if
you do this:
mouse = event.Mouse(win=win)
later on you can detect where someone touches the screen by using
mouse.getPos(), right? This is like mouse hovering because its just
the position, there's nothing about being pressed or clicked, etc.

How does the programmer tell if someone is no longer touching the screen?

Perhaps when using an actual mouse (not touchscreen), you need to do
something to allow the mouse to be moved, like:
#wait until move out of the square
while bluesquare.contains(mouse):
if not havePyglet:
continue
try:
pyglet.media.dispatch_events()
wins =
pyglet.window.get_platform().get_default_display().get_windows()
for win in wins: win.dispatch_events()
except:
break

But I don't know what (if anything) you'd need to do for a touchscreen.

Jonathan Peirce

unread,
Apr 10, 2013, 10:42:19 AM4/10/13
to psychop...@googlegroups.com
For the only touchscreen I ever used, a finger press was akin to a
button press on the mouse (not like a hover) so I find this one surprising.
Jon

Jan

unread,
Apr 11, 2013, 3:25:03 PM4/11/13
to psychop...@googlegroups.com
I use a similar piece of code for the same reason, except mine is the other way around. I think you have to wait for the click release before you collect the response. Assuming that touching the screen is equivalent to clicking, this should do the trick:


#wait unitl mouse is released
while mouse.getPressed():
     pass #do nothing

if mouse.getPressed() and bluesquare.contains(mouse):
   response="1"
   trials.finished=True


Jan

Lily FitzGibbon

unread,
Sep 17, 2013, 5:31:48 AM9/17/13
to psychop...@googlegroups.com
I have just got around a similar problem with a touchscreen by using the mouseMoved function:

# Each frame check if the mouse has moved
if mouse.mouseMoved():
# if mouse has moved, check if it has moved into image
if image.contains(mouse):
# if mouse in image, end routine
countinueRoutine = False
# Get the current position of the mouse, this is important because mouseMoved is relative to the last getPos call
mouse.getPos()

I hope this is useful,

Best,

Lily

Amy Bland

unread,
Sep 21, 2013, 12:52:26 PM9/21/13
to psychop...@googlegroups.com
That worked perfectly Lily, thank you so much. This is the only solution that has worked effectively with my touchscreen so this is a massive help.

Thanks again, I can now use all my tasks with touchscreen!


--
You received this message because you are subscribed to a topic in the Google Groups "psychopy-users" group.

To unsubscribe from this group and all its topics, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.

Kathryn Schuler

unread,
Mar 9, 2014, 6:53:51 PM3/9/14
to psychop...@googlegroups.com
I just wanted to reply to this thread so that other people who are searching for specific solutions might find answers more effectively.  The "mouseMoved" solution provided by Lily is very clever and also worked for me!  I was having difficulty getting a microsoft surface (touch screen) to register mouse-clicks.  For some reason it always waited for double-clicks instead of the single-click, which I needed for reaction time.  I typically use an Elo Touch screen and that has always responded like a regular mouse (as if the computer didn't know any difference), so this was completely baffling for me.  For some reason the surface touch was different (I suspect because of the multi-touch features / windows 8/ being possessed).  mouse.getPressed() just returns [0,0,0] unless there is a double click.  The mouse itself, however, will trigger mouse.getPressed() on a single click.  There is something different between the touch aspect and the mouse.  I tried 1,000,000 things, including every possible strategy one could think of for changing this feature on the surface itself.  No dice.  This works just as well.  

So if you have a tablet (or surface) that you are using to collect touch input, but can't get usual mouse.getPressed() tactics to work, try mouse.mouseMoved()

Someday when I am bored, I am going to look into the kivy library, which might provide some solutions (and fun stuff) for multi-touch surfaces (http://kivy.org/#home)

Thanks.
Katie

Julia Hübner

unread,
Jan 11, 2016, 11:19:08 AM1/11/16
to psychopy-users
Hello everyone,

sorry for bothering you, though all these initiaI posts are a little older... but... I am still facing the same problem as you described here (trying to run an experiment on a windows tablet, wanting to measure reaction times for decisions indicated via touches on the tablet (and also the position of the touch has to be recorded) but only double-clicks get counted).
Even worse: I am a total beginner with Python. I tried to make up the biggest parts of the experiment within the builder view and then to insert the "mouseMoved"solution by Lily in a code component. For days I am getting the following error message:

...line 108, in <module>
if mouse.mouseMoved ():
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.01-py2.7.egg\psychopy\event.py", line 421, in mouseMoved
if self.prevPos[0] <> self.lastPos[0]: return True
TypeError: 'NoneType' object has  no attribute '__getitem__'

Really, I am desperate!! No one around me is into PsychoPy oder Python, and though I tried a few things, I don't even really get the error message....
I really would appreciate, if someone had a clue....

Thanks so much,
Julia

Ben McCartney

unread,
Jun 9, 2016, 6:10:32 AM6/9/16
to psychopy-users
Hi Julia,

I imagine this is too late to be of use to you, but should anyone else face the same issue implementing Lilly's solution I solved it by calling getPos() before the loop started to make sure it happened before the first check of mouseMoved().

Ben

Danny Garside

unread,
Jun 30, 2016, 6:31:58 AM6/30/16
to psychopy-users
Hi all,
I'm a PhD student just setting out on a touch screen/visual psychophysics experiment. 
Does anyone have recommendations for papers/other sources to look at for info on the range of calibration techniques used for preparing a touch screen.
(Interested in spatial more than colour/linearity etc.)
Currently thinking about touch accuracy and centre bias...

DG
Reply all
Reply to author
Forward
0 new messages