# GetMouse for Windows

**URL:** <https://psychtoolbox.discourse.group/t/getmouse-for-windows/1452>\
**Category:** Uncategorized\
**Created:** [July 31, 2001, 4:51pm UTC](https://psychtoolbox.discourse.group/t/getmouse-for-windows/1452 "2001-07-31T16:51:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [July 31, 2001, 4:51pm UTC](https://psychtoolbox.discourse.group/t/getmouse-for-windows/1452/1 "2001-07-31T16:51:06Z")

</div>

David Burr, [daveb@...](mailto:daveb@...)  
  

> \> Also, can you confirm that your getmouse does not work on the PC? It  
> \> should  
> \> give [x, y, button], but button is always zero. Do any of the mouse  
> \> routines  
> \> detect a button press on the PC (I need it for a touchscreen)? This sort  
> \> of  
> \> stuff is a nightmare with matlab (GUIs etc, that you cannot escape from).  
> \>

Dave,  
  
Denis forwarded your question to me. I am copying my reply to the  
psychtoolbox forum, in case anyone there has something helpful to add.  
  
GetMouse worked when I was using it on Windows 98. Last week I  
noticed that it was not detecting button presses under Windows2000.  
I have been working on that problem, I hope to have a fix within the  
next few days.  
  
GetClicks works under windows 2000 and is a suitable substitute for  
GetMouse in some applications. GetClicks, unlike GetMouse, waits for  
a click. Note that John Schlerf uncovered a bug in GetClicks  
([http://groups.yahoo.com/group/psychtoolbox/message/470)](http://groups.yahoo.com/group/psychtoolbox/message/470)), which is  
that it fails if you use SCREENOpenWindow to change the bit depth of  
the display. However, that bug is easy to avoid.  
  
Best,  
  
Allen

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [July 31, 2001, 8:51pm UTC](https://psychtoolbox.discourse.group/t/getmouse-for-windows/1452/2 "2001-07-31T20:51:29Z")

</div>

I've found that GetMouse seems to work a lot better for me if I put   
in a 'WaitBlanking' command when I call it repeatedly (I'm running   
Windows 2000). I was using GetMouse once in a loop to track the   
position of the cursor, and I set the loop up to break when the mouse   
was clicked. It would hardly ever register the click; I could only   
break the loop by clicking multiple times as fast as I could. I   
tried adding short pause statements and checking for clicks on every   
other line in the loop, but it never worked. Once I added   
a 'WaitBlanking' command, though, it worked beautifully.  
  
While we're on the subject of pshychtoolbox's mouse commands, I   
noticed that ButtonAvail doesn't quite work right. Here's some code   
I wrote to demonstrate:  
  
function z = mousedemo  
  
main = screen(0,'OpenWindow');  
  
for flickers = 1:240  
 z(flickers) = buttonavail;  
 screen(main,'WaitBlanking',1);  
end  
  
screen('CloseAll');  
  
What happens when I run this is that z will be zero until the point   
when the mouse is clicked. From that point on, regardless of the   
status of the mouse, it will be 1.  
  
Maybe this will be helpful in figuring out how the event queue works   
in Win2k?  
  
John

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [August 7, 2001, 7:48pm UTC](https://psychtoolbox.discourse.group/t/getmouse-for-windows/1452/3 "2001-08-07T19:48:30Z")

</div>

I have attached new versions of GetMouse.dll and its help file,  
GetMouse.m, to this message. Two changes have been made in GetMouse:  
  
1- The previous version of GetMouse failed to detect mouse presses  
when used with some versions of Windows and Matlab. The new version  
has been tested with Matlab 6 under Windows 2000 and confirmed to  
work, whereas the old version failed with that combination. The new  
version is expected to work with Matlab versions 5.x and 6.x, and with  
Windows 95, 98, NT, 2000, and ME. It has not yet been tested with most  
of those and I would be glad to hear the results if anyone tries it  
with any combination of Matlab and Windows other than the one  
combination already tested.  
  
2- Under Windows, the "button" return argument is now a 1x4 matrix,  
with each element representing one mouse button. See the new help  
file for details and examples.  
  
  
Allen

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [August 9, 2001, 2:50am UTC](https://psychtoolbox.discourse.group/t/getmouse-for-windows/1452/4 "2001-08-09T02:50:34Z")

</div>

[John\_Schlerf@...](mailto:John_Schlerf@...) wrote:  
  

> \> I tried running the new GetMouse using MATLAB 5.3.1 under Windows  
> \> 2000. I get the following error message:  
> \>  
> \> » GetMouse  
> \> 'C:\Program' is not recognized as an internal or external command,  
> \> operable program or batch file.  
> \> ??? Invalid MEX-file  
> \>  
> \> On a second computer, also running MATLAB 5.3.1 under Win2k, I get  
> \> the following:  
> \>  
> \> » GetMouse  
> \> Error loading C:\Documents.  
> \> ??? Invalid MEX-file  
> \>  
> \> With MATLAB 6.1, though, it works very well.

John,  
  
Thank you for the feedback. I am not sure why that happens.  
  
Maybe Matlab is getting confused because it does not know about path names  
which have spaces in them. That is suggested by this line from you error  
message:  
'C:\Program' is not recognized as an internal or external command,  
  
'C:\Program Files' is the the full name of that directory. It looks as if  
Matlab was told to find something in a path which includes the string  
"Program Files", mis-parsed the path string because of the space, and ended  
up looking for a file named "'C:\Program" instead. Maybe the warning, "???  
Invalid MEX-file" is a red herring; Matlab has not really tried to load a  
binary into memory and been unable to find the "mexFunction" symbol, instead  
Matlab is guessing that it did that, since running what you asked it to did  
not work. The Matlab API guide does say that Matlab issues the "???  
Invalid MEX-file" file warning to mean that "Matlab is unable to recognize  
your MEX-file as being valid." I suppose that could apply here, even if the  
reason that Matlab has not recognized the MEX-file as being valid is that it  
never found the file because it got confused by space character within a path  
string.  
  
Same thing with the "Error loading C:\Documents" message, it is really  
looking for something on a path along which lies the directory "C:\Documents  
and Settings".  
  
The big mystery is, why would Matlab be looking down paths which include  
those directories ? If you check the Matlab path settings, are there any  
paths which include the directories "Program Files" or "Documents and  
Settings". And, just to be certain: Other psychtoolbox functions on those  
machines work ? All you've done is to replace the older versions of  
GetMouse.dll and GetMouse.m with the new versions ?  
  
Best,  
  
Allen

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [August 9, 2001, 2:34pm UTC](https://psychtoolbox.discourse.group/t/getmouse-for-windows/1452/5 "2001-08-09T14:34:30Z")

</div>

--- In psychtoolbox@y..., "Allen W. Ingling" \<ingling@c...\> wrote:  

> \>   
> \> John,  
> \>   
> \> Thank you for the feedback. I am not sure why that happens.  
> \>   
> \> Maybe Matlab is getting confused because it does not know about

path names  

> \> which have spaces in them. That is suggested by this line from you

error  

> \> message:  
> \> 'C:\Program' is not recognized as an internal or external command,  
> \>   
> \> 'C:\Program Files' is the the full name of that directory. It looks

as if  

> \> Matlab was told to find something in a path which includes the

string  

> \> "Program Files", mis-parsed the path string because of the space,

and ended  

> \> up looking for a file named "'C:\Program" instead. Maybe the

warning, "???  

> \> Invalid MEX-file" is a red herring; Matlab has not really tried to

load a  

> \> binary into memory and been unable to find the "mexFunction"

symbol, instead  

> \> Matlab is guessing that it did that, since running what you asked

it to did  

> \> not work. The Matlab API guide does say that Matlab issues

the "???  

> \> Invalid MEX-file" file warning to mean that "Matlab is unable to

recognize  

> \> your MEX-file as being valid." I suppose that could apply here,

even if the  

> \> reason that Matlab has not recognized the MEX-file as being valid

is that it  

> \> never found the file because it got confused by space character

within a path  

> \> string.  
> \>   
> \> Same thing with the "Error loading C:\Documents" message, it is

really  

> \> looking for something on a path along which lies the

directory "C:\Documents  

> \> and Settings".  
> \>   
> \> The big mystery is, why would Matlab be looking down paths which

include  

> \> those directories ? If you check the Matlab path settings, are

there any  

> \> paths which include the directories "Program Files" or "Documents

and  

> \> Settings". And, just to be certain: Other psychtoolbox functions on

those  

> \> machines work ? All you've done is to replace the older versions of  
> \> GetMouse.dll and GetMouse.m with the new versions ?  
> \>   
> \> Best,  
> \>   
> \> Allen

My path settings do contain references to My Documents (actually,   
I've got Psychtoolbox installed as a folder in My Documents), and   
MATLAB has never given me trouble about that in the past. The old   
GetMouse.dll works, and all other Psychtoolbox functions work. So I   
really don't know what could be the trouble.  
  
There is one quirk about one of my MATLAB installations: I can't   
compile mex functions. I can on the second machine (which gave the   
C:\documents error), so I'm not entirely sure what's going on there.   
It doesn't really affect me, especially since we're in the process of   
upgrading to the latest release of MATLAB.  
  
Anyway, thanks for the suggestions.  
  
 John

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [August 9, 2001, 3:33pm UTC](https://psychtoolbox.discourse.group/t/getmouse-for-windows/1452/6 "2001-08-09T15:33:28Z")

</div>

I'm not entirely sure what's going on, but with the new Psychtoolbox   
I get a lot of palette errors when I try to use Screen's FillRect   
command on an offscreen window. The program still executes   
perfectly, but once it has ended I see a lot of error messages. In   
MATLAB 6.1 I see "Could not Select Palette for use.", and in MATLAB   
5.3.1 I see something like "winInfo --\> hpal == NULL SCREENFillRect   
could not select Palette for use"  
  
It isn't a big deal, since the programs still run properly. I was   
just a little concerned since I never had any problem with the older   
version of psychtoolbox.  
  
One other problem I noticed seems to only occur with MATLAB 6.1, but   
maybe it's related. I'm having color problems with 32 bit images.   
This used to happen to me with 5.3.1 before I realized that the data   
type should be uint8. But in this new version, when I try to show an   
image which should be gray it comes out yellow. The same code works   
fine on the earlier version of MATLAB, so I'm stumped.

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [August 9, 2001, 5:02pm UTC](https://psychtoolbox.discourse.group/t/getmouse-for-windows/1452/7 "2001-08-09T17:02:57Z")

</div>

[John\_Schlerf@...](mailto:John_Schlerf@...) wrote:  
  

> \> My path settings do contain references to My Documents (actually,  
> \> I've got Psychtoolbox installed as a folder in My Documents), and  
> \> MATLAB has never given me trouble about that in the past. The old  
> \> GetMouse.dll works, and all other Psychtoolbox functions work. So I  
> \> really don't know what could be the trouble.

If you would be willing to spend some more time on this, please try the  
following:  
  
1- Make sure that Matlab is installed in directory path with which has no  
spaces in the path name. For example, Matlab is installed on my computer in  
C:\matlabR12  
  
2- Place the Psychtoolbox folder inside the toolbox folder inside the matlab  
folder. On my machine it is here: C:\matlabR12\toolbox\PsychToolbox  
  
3- Make sure that you have the new versions of GetMouse.dll and GetMouse.m  
inside the Psychtoolbox's PsychBasic folder. Mine looks like this:  
C:\matlabR12\toolbox\PsychToolbox\PsychBasic\GetMouse.dll  
C:\matlabR12\toolbox\PsychToolbox\PsychBasic\GetMouse.m  
  
4- Set the Matlab path to include the psychtoolbox folder and recursively all  
folders underneath.  
  
5- Try GetMouse again.  
  
Best,  
  
Allen

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [August 9, 2001, 7:40pm UTC](https://psychtoolbox.discourse.group/t/getmouse-for-windows/1452/8 "2001-08-09T19:40:11Z")

</div>

Here's some code that generates the palette error:  
  
window = screen(0,'OpenWindow');  
window2 = screen(window,'OpenOffscreenWindow');  
screen(window2,'FillRect',2);  
screen('CloseAll');  
  
  
As far as the other problem I mentioned, I tried running screendemo,   
but it gave me an error. I traced the error to a line of code in   
ask.m, and the offending command is:  
  
screenRect=SCREEN(window,'Rect');  
  
  
I tried typing screen Rect? and screen('Rect?'), but they would not   
return anything. This is in MATLAB 6.1. I have MATLAB 5.3.1 on the   
same system, with the same installation of PsychToolbox in the path,   
and screen('Rect?') works perfectly, which is a bit confusing.  
  
My video card is an NVidia Riva TNT2, using Microsoft's driver.   
There's no version given, just 9/30/1999.  
  
Here's a quick example of what I'm doing to get these yellow images:  
  
sphere;  
colormap gray;  
shading flat;  
axis off;  
G = getframe;  
window = screen(0,'OpenWindow');  
screen(window,'PutImage',G.cdata);  
getchar;  
screen('CloseAll');  
  
  
When this is run, the sphere shows up yellow. On my system, G.cdata   
is a 343x435x3 uint8, and the following statements return 1 (true):  
  
all(all(G.cdata(:,:,1) == G.cdata(:,:,2)))  
all(all(G.cdata(:,:,1) == G.cdata(:,:,3)))  
  
  
So this should be coming up gray, at least as far as I can reckon.   
But it doesn't like to.

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [August 9, 2001, 7:50pm UTC](https://psychtoolbox.discourse.group/t/getmouse-for-windows/1452/9 "2001-08-09T19:50:12Z")

</div>

--- In psychtoolbox@y..., "Allen W. Ingling" \<ingling@c...\> wrote:  

> \>   
> \>   
> \> John\_Schlerf@b... wrote:  
> \>   
> \> \> My path settings do contain references to My Documents (actually,  
> \> \> I've got Psychtoolbox installed as a folder in My Documents), and  
> \> \> MATLAB has never given me trouble about that in the past. The old  
> \> \> GetMouse.dll works, and all other Psychtoolbox functions work.

So I  

> \> \> really don't know what could be the trouble.  
> \>   
> \> If you would be willing to spend some more time on this, please try

the  

> \> following:  
> \>   
> \> 1- Make sure that Matlab is installed in directory path with which

has no  

> \> spaces in the path name. For example, Matlab is installed on my

computer in  

> \> C:\matlabR12  
> \>   
> \> 2- Place the Psychtoolbox folder inside the toolbox folder inside

the matlab  

> \> folder. On my machine it is here: C:\matlabR12\toolbox\PsychToolbox  
> \>   
> \> 3- Make sure that you have the new versions of GetMouse.dll and

GetMouse.m  

> \> inside the Psychtoolbox's PsychBasic folder. Mine looks like this:  
> \> C:\matlabR12\toolbox\PsychToolbox\PsychBasic\GetMouse.dll  
> \> C:\matlabR12\toolbox\PsychToolbox\PsychBasic\GetMouse.m  
> \>   
> \> 4- Set the Matlab path to include the psychtoolbox folder and

recursively all  

> \> folders underneath.  
> \>   
> \> 5- Try GetMouse again.  
> \>   
> \> Best,  
> \>   
> \> Allen

I went to the second computer, which has MATLAB installed in   
c:\matlabR11, and moved psychtoolbox into the toolbox folder   
(c:\matlabR11\toolbox\PsychToolbox). Then I went into the path   
browser and removed any reference to any folder with a space in the   
name, and installed PsychToolbox and every subfolder. Then typing   
GetMouse gives me the following error:  
  
Error loading libmex.dll from C:\MATLABR11  
\toolbox\PsychToolbox\PsychBasic\GetMouse.dll.  
Error loading C:\MATLABR11  
\toolbox\PsychToolbox\PsychBasic\GetMouse.dll.  
??? Invalid MEX-file  
  
This is slightly different from what it was doing before; but it   
still doesn't work.
