# Windows7 use of touchscreen monitor as mouse - unexpected behavior

**URL:** <https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317>\
**Category:** Coding\
**Created:** [October 20, 2016, 3:04pm UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317 "2016-10-20T15:04:51Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![SarahT](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SarahT](https://discourse.psychopy.org/u/SarahT)\
**Post date:** [October 20, 2016, 3:04pm UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/1 "2016-10-20T15:04:51Z")

</div>

Hi all,

I’m running the latest standalone version of Psychopy on a Windows 7 machine. We have two monitors connected that are mirrored. The primary display or screen 0 (ViewSonic touchscreen) is the one participants are using during the experiment. Outside of PsychoPy the touch screen works as expected, meaning that finger pressed are interpreted as single mouse (left button) clicks as expected.

I’ve pre-tested my experiment using an ordinary mouse - the script uses the functions mouse.getPressed( ) and mouse.isPressedIn( ) during two different routines - and everything works fine.

With the touchscreen, however, a single finger press/touch is not recognized as a single left-button click. I figured out that I need to touch the screen in one position then move it and release it in a different position - so more of a swiping motion than a click.

What makes this even stranger is that in the logfile the single finger presses are registered exactly as one would expect from a single mouse click.

Here are some parts from the beginning of the experiment. The instructions are being shown and the participant is asked to touch the screen to carry on. The first few logged responses are single finger presses that fail to end that routine.

```auto
9.8566 EXP instr: autoDraw = True
11.4736 DATA Mouse: Left button down, pos=(1263,334)
11.4736 DATA Mouse: Left button up, pos=(1263,334)
16.7396 DATA Mouse: Left button down, pos=(1437,308)
16.7397 DATA Mouse: Left button up, pos=(1437,308)
20.3412 DATA Mouse: Left button down, pos=(1423,384)
20.3413 DATA Mouse: Left button up, pos=(1423,384)
20.4728 DATA Mouse: Left button down, pos=(1423,384)
20.4729 DATA Mouse: Left button up, pos=(1423,384)
25.0736 DATA Mouse: Left button down, pos=(1204,663)
25.0737 DATA Mouse: Left button up, pos=(1204,663)
27.8057 DATA Mouse: Left button down, pos=(1218,371)
27.8057 DATA Mouse: Left button up, pos=(1218,371)
29.8221 DATA Mouse: Left button down, pos=(984,287)
29.8346 EXP Imported lists/test_list.csv as conditions, 16 conditions, 31 params
29.8351 EXP Created sequence: sequential, trialTypes=16, nReps=1, seed=None
29.8362 EXP New trial (rep=0, index=0): {'R_item': u'R_T_spec_4', 'br': u'Sperber', 'item': 4, 'bl': u'Geier', 'confusion': u'Falken', 'cond_code': 120, 'item_code': 4, 'rel_code': 160, 'cond': u'spec_sym', 'distractor1': u'Geier', 'distractor2': u'Sperber', 'L_item': u'L_T_spec_4', 'conf_loc': u'topright', 'R_sentence': u'Karin bestaunte morgens zw\xf6lf Falken', 'sem_cue': u'Raubv\xf6gel', 'correct_loc': u'topleft', 'stim': u'audio_training/T_spec_4.wav', 'probed_code': 181, 'fixdur1': 138, 'L_sentence': u'Thomas zeichnete mittags drei Adler', 'fixdur2': 95, 'tr': u'Falken', 'presented2': u'Falken', 'presented1': u'Adler', 'tl': u'Adler', 'L_final': u'Adler', 'rel_cue': u'pics/20_80.png', 'sem_code': 130, 'R_final': u'Falken', 'correct': u'Adler', 'probed': u'L'}
29.8551 EXP instr: autoDraw = False
29.8551 EXP fix1: autoDraw = True
30.1058 DATA Mouse: Left button up, pos=(1088,284)
32.1466 EXP Set sound=audio_training/T_spec_4.wav
32.1550 EXP fix1: autoDraw = False

```

Using the mouse instead of touch screen:

```auto
9.5666 EXP instr: autoDraw = True
10.3668 DATA Mouse: Left button down, pos=(772,647)
10.3784 EXP Imported lists/test_list.csv as conditions, 16 conditions, 31 params
10.3789 EXP Created sequence: sequential, trialTypes=16, nReps=1, seed=None
10.3798 EXP New trial (rep=0, index=0): {'R_item': u'R_T_spec_4', 'br': u'Sperber', 'item': 4, 'bl': u'Geier', 'confusion': u'Falken', 'cond_code': 120, 'item_code': 4, 'rel_code': 160, 'cond': u'spec_sym', 'distractor1': u'Geier', 'distractor2': u'Sperber', 'L_item': u'L_T_spec_4', 'conf_loc': u'topright', 'R_sentence': u'Karin bestaunte morgens zw\xf6lf Falken', 'sem_cue': u'Raubv\xf6gel', 'correct_loc': u'topleft', 'stim': u'audio_training/T_spec_4.wav', 'probed_code': 181, 'fixdur1': 138, 'L_sentence': u'Thomas zeichnete mittags drei Adler', 'fixdur2': 95, 'tr': u'Falken', 'presented2': u'Falken', 'presented1': u'Adler', 'tl': u'Adler', 'L_final': u'Adler', 'rel_cue': u'pics/20_80.png', 'sem_code': 130, 'R_final': u'Falken', 'correct': u'Adler', 'probed': u'L'}
10.3999 EXP instr: autoDraw = False
10.3999 EXP fix1: autoDraw = True
10.5001 DATA Mouse: Left button up, pos=(772,647)
12.6919 EXP Set sound=audio_training/T_spec_4.wav
12.6919 EXP window1: recordFrameIntervals = False
12.6998 EXP fix1: autoDraw = False

```

Is this a timing issue? Is seems that the button down and button up responses are logged all most at the same time for the touch screen. I’ve already tried holding my finger down on the screen a bit longer but it seems that moving it to a different location is the only solution for now.

Any ideas on how to solve this problem? I’m working with older participants who sometimes have trouble using a mouse, so I would like to avoid asking them to swipe instead of touch/click on the screen.

Thanks,  
Sarah

---

<div class="post-metadata">

**Author:** ![Oli](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/oli/32/520_2.png) [@Oli](https://discourse.psychopy.org/u/Oli)\
**Post date:** [October 20, 2016, 4:29pm UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/2 "2016-10-20T16:29:49Z")

</div>

Hi Sarah - this may be because the touch signal is subject to much more interference than a mouse click - you’ll see that the up and down on the touch screen are much closer than the mouse click up and down. Check this thread out and see if that helps at all:

> [@Creating Clickable Buttons on Windows Surface (Touchscreen)](http://discourse.psychopy.org/t/creating-clickable-buttons-on-windows-surface-touchscreen/1277):
>
> Hi all, I’d like participants to be able to touch a button on either side of the screen of a Windows Surface for an on-site IAT test. Thus far, I’ve run into a few issues. The first is that, in order for the program to move forward, the screen has to be tapped twice. I’m not sure exactly why this is. I used Builder to create a click event so that when the mouse is clicked (or in this case, the equivalent event of ‘screen is touched’) the routine ends. However, this doesn’t seem to be translati…

BW

Oliver

---

<div class="post-metadata">

**Author:** ![SarahT](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SarahT](https://discourse.psychopy.org/u/SarahT)\
**Post date:** [October 21, 2016, 1:34pm UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/3 "2016-10-21T13:34:41Z")

</div>

Hi Oliver,

thank you for your response. I followed your instructions from the linked thread but unfortunately this didn’t solve my problem. Using the additional while loop, “Pressed” is only set to “True” if I hold down my finger and move it slightly. So the single finger presses are again not registered as single mouse button presses. I also reasoned that it might have to do with the fact that the up and down are much closer together than those of an actual mouse.

Any other clues on how to solve this?

Thanks,  
Sarah

---

<div class="post-metadata">

**Author:** ![Oli](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/oli/32/520_2.png) [@Oli](https://discourse.psychopy.org/u/Oli)\
**Post date:** [October 22, 2016, 4:47pm UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/4 "2016-10-22T16:47:54Z")

</div>

Hi Sarah,

I don’t have the same set up as you so I can’t do any testing or checking. Have you tried it on a single monitor?

BW

Oli

---

<div class="post-metadata">

**Author:** ![luca.filippin](https://avatars.discourse-cdn.com/v4/letter/l/ac91a4/32.png) [@luca.filippin](https://discourse.psychopy.org/u/luca.filippin)\
**Post date:** [October 23, 2016, 10:30am UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/5 "2016-10-23T10:30:28Z")

</div>

Hi Sarah,  
I suspect that depends on 3 facts:

1 - from the log you provided looks like a touch is translated in 2 almost instantaneous events of PRESS and RELEASE  
2 - the mouse component does store (asynchronously) only the last event occurred  
3 - within a routine loop the mouse is checked at every flip(), which means roughly every 15 ms on average (on 60Hz screens), depending on the vertical refresh frequency of your screen

If the mouse events are triggered at a higher frequency, you’re going to miss some or all of them very likely.  
Of course normally everything works fine as it’s hard to imagine someone clicking and releasing the mouse button so fast.

Anyway, I had a similar problem in the past. To workaround it, I changed the callback \_onPygletMousePress and \_onPygletMouseRelease (in the [event.py](http://event.py) module) so that they would store the mouse history if I’d set programmatically a special flag. Then I added a a couple functions: one to set the flag, the other to be used within the psychopy routine loop to retrieve and empty the mouse history in between one call and the successive.

I should probably ask to introduce this feature to the future version of PsychoPy.

L.

---

<div class="post-metadata">

**Author:** ![SarahT](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SarahT](https://discourse.psychopy.org/u/SarahT)\
**Post date:** [October 24, 2016, 8:17am UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/6 "2016-10-24T08:17:53Z")

</div>

Hi Luca,

thanks for your reply. Your explanations make a lot of sense and made me understand the cause of the problem I’m dealing with a lot better.

Would you mind sharing the code for the adaptations you’ve done to the [event.py](http://event.py) module? Logically I can follow your proposed changes but I’m not sure I would be able to implement them myself.  
I think it would be great if such features could be generally incorporated since I’m probably not the only one facing these issues.

Thanks again,  
Sarah

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/richard/32/6389_2.png) [@richard](https://discourse.psychopy.org/u/richard)\
**Post date:** [October 24, 2016, 8:21am UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/7 "2016-10-24T08:21:25Z")

</div>

If you just need to register button presses _anywhere_, you could also use ioHub:

```auto
from __future__ import print_function
from psychopy import iohub

io = iohub.launchHubServer()
mouse = io.devices.mouse
mouse.clearEvents()

while True:
    e = mouse.getEvents(event_type=(iohub
                                    .EventConstants
                                    .MOUSE_BUTTON_PRESS))

    if e:
        break

print('Received button press!')

```

However, there is no equivalent to `event.Mouse.isPressedIn()` in ioHub, I’m afraid.

---

<div class="post-metadata">

**Author:** ![SarahT](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SarahT](https://discourse.psychopy.org/u/SarahT)\
**Post date:** [October 24, 2016, 8:38am UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/8 "2016-10-24T08:38:50Z")

</div>

Thanks Richard, this would definitely help with the instructions routine but unfortunately I’m relying on `event.Mouse.isPressedIn()` for the responses at the end of each trial.

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/richard/32/6389_2.png) [@richard](https://discourse.psychopy.org/u/richard)\
**Post date:** [October 24, 2016, 8:57am UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/9 "2016-10-24T08:57:26Z")

</div>

If your stimuli inherit from `ShapeStim`, they will have a `contains()` method, which you could employ. The following example uses ioHub to check whether a button press occurred inside a circle.

_NB: I’m not sure whether this works with other units than `pix`. **It will certainly only work in fullscreen mode!** _

```auto
from __future__ import print_function

from psychopy import iohub
from psychopy.visual.window import Window
from psychopy.visual.circle import Circle

io = iohub.launchHubServer()
mouse = io.devices.mouse

win = Window(units='pix', fullscr=True)
circle = Circle(win, size=300)
circle.draw()
win.flip()

mouse.clearEvents()

while True:
    e = mouse.getEvents(event_type=(iohub
                                    .EventConstants
                                    .MOUSE_BUTTON_PRESS))

    if e:
        x, y = e[0].x_position, e[0].y_position

        if circle.contains((x, y), units='pix'):
            print('Received button press!')
            break

win.close()
io.quit()

```

---

<div class="post-metadata">

**Author:** ![SarahT](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SarahT](https://discourse.psychopy.org/u/SarahT)\
**Post date:** [October 24, 2016, 9:12am UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/10 "2016-10-24T09:12:47Z")

</div>

Yes, I’m using `visual.Rect` to present four response boxes to choose from so your suggestion should work in this case as well.

I’ll give this a try and report back!

Thanks everyone,  
Sarah

---

<div class="post-metadata">

**Author:** ![luca.filippin](https://avatars.discourse-cdn.com/v4/letter/l/ac91a4/32.png) [@luca.filippin](https://discourse.psychopy.org/u/luca.filippin)\
**Post date:** [October 24, 2016, 12:14pm UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/11 "2016-10-24T12:14:06Z")

</div>

Hi Sarah,  
mine was a patch on the fly, not actually integrated with the Mouse component. I created a new component, apart. So, as you’re using Mouse.isPressedIn() it won’t work straightaway so I should adapt it to make it usable for your purposes and I’d need a bit of time. I see that Richard has provided you an alternative solution. If that works, I’d prefer to wait before posting any code.

Cheers,  
L.

---

<div class="post-metadata">

**Author:** ![SarahT](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SarahT](https://discourse.psychopy.org/u/SarahT)\
**Post date:** [October 25, 2016, 10:53am UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/12 "2016-10-25T10:53:57Z")

</div>

Hi all,

just to provide some feedback - I’ve tried the mouse alternative Richard suggested and it works! Thus far I only had time to test the minimalistic example that Richard provided but I don’t see why it should not work for my actual experiment as well.  
I have only one related question that I couldn’t figure out from the details provided in the reference manual on iohub - since I want to compute reaction times for the responses at the end of the trial, how do I access the time stamp for the occurrence of events monitored by `ìo.devices.mouse.getEvents()` ?

Thanks,  
Sarah

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/richard/32/6389_2.png) [@richard](https://discourse.psychopy.org/u/richard)\
**Post date:** [October 25, 2016, 12:34pm UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/13 "2016-10-25T12:34:29Z")

</div>

> [@SarahT](#):
>
> how do I access the time stamp for the occurrence of events monitored by ìo.devices.mouse.getEvents() ?

In the example above, you would access the time stamp of the first button press event via `e[0].time`. The time base is the same as the PsychoPy time base (monotonically increasing). So you would commonly do something like this (untested):

```auto
circle.draw()
mouse.clearEvents()

t0 = win.flip()

while True:
    e = mouse.getEvents(event_type=(iohub
                                    .EventConstants
                                    .MOUSE_BUTTON_PRESS))

    if e:
        break

rt = e[0].time - t0
print('RT was %.3f sec' % rt)

```

Good luck!

---

<div class="post-metadata">

**Author:** ![Tamas\_Andrei\_Foldes](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tamas_andrei_foldes/32/14758_2.png) [@Tamas\_Andrei\_Foldes](https://discourse.psychopy.org/u/Tamas_Andrei_Foldes)\
**Post date:** [October 2, 2018, 6:12pm UTC](https://discourse.psychopy.org/t/windows7-use-of-touchscreen-monitor-as-mouse-unexpected-behavior/1317/14 "2018-10-02T18:12:19Z")

</div>

This thread is old but if anyone is on the “touchscree-train” the current equivalent of the mouse testing example:

```auto
from __future__ import print_function
from psychopy import iohub

io = iohub.launchHubServer()
mouse = io.devices.mouse
mouse.clearEvents()

while True:
    e = mouse.getEvents(event_type=(iohub
									.constants
                                    .EventConstants
                                    .MOUSE_BUTTON_PRESS))

    if e:
        print(e)
        break

print('Received button press!')
io.quit()

```

will result in print(e) containing:  
[‘P’, ‘C’, ‘_’, ‘D’, ‘E’, ‘V’, ‘I’, ‘C’, ‘E’, '_’, ‘R’, ‘U’, ‘N’, ‘T’, ‘I’, ‘M’, ‘E’, ‘\_’, ‘E’, ‘R’, ‘R’, ‘O’, ‘R’]

Psychopy: 1.9.2  
Python: 3.5.6 Anaconda
