Skip to main content
GameDev.net gamedev.net
🔒 Locked

Checking whether or not a mouse is connected

Started by MentalMan Feb 10, 2006 at 6:52 AM 7 replies 1.4k views
Original Post
MentalMan
MentalMan
Hello, Is there a C++ API that lets me, directly or otherwise, check whether or not a USB mouse is connected? Google was no help to me and neither was MSDN. Please help. -MentalMan
Shamino
Shamino
I may be wrong, but I believe this has something to do with simply checking which IRQ's are active, the mouse and keyboard both have a set IRQ which is determined by the operating system. I'm afraid I don't know how to do this, but I believe that might aid you in your search to finding an answer.

The idea is that the IRQ won't be doing its job when the device isn't connected (taking precedence over other things..).. The IRQ is simply the number of priority the device has when it comes to processing input..
----------------------------------------------------------Rating me down will only make me stronger.----------------------------------------------------------
mfawcett
mfawcett
In Win32, you can use GetSystemMetrics with SM_MOUSEPRESENT.
--Michael Fawcett
MentalMan
MentalMan
Ok, I'll look that up.

EDIT: I used this code:
			if(!GetSystemMetrics(SM_MOUSEPRESENT))			{				SetTextColor(hdc,RGB(0,0,0));				TextOut(hdc,0,0,"NO MOUSE",strlen("NO MOUSE"));			}


But when I unplug my mouse nothing happens. What's wrong?

Second EDIT:

Quote:
Nonzero if a mouse is installed; otherwise, 0. This value is rarely zero, because of support for virtual mice and because some systems detect the presence of the port instead of the presence of a mouse.


I reckon this is the problem. I'll check to see if there's another function..

Third EDIT:

SM_CMOUSEBUTTONS doesn't work either and I can't find another one. Please help.

[Edited by - MentalMan on February 11, 2006 10:26:37 AM]
Daaark
Daaark
Just try checking the cursor position over a few calls. The cursor can't move if there is no mouse. Is there a reason you need to know if there is a mouse other than that your game requires one?
sit
sit
what if someone has a tablet? a track-point? a touch pad? a little silver dot on their forhead?

please can you describe what you're trying to do and why trying to see if someone has a mouse is necescary?
MentalMan
MentalMan
I am trying to let the application do something when someone unplugs their mouse.
I'm trying to do this because they keep getting stolen at my school, and they want to catch some of them while doing it. (Well, that and a bit of practice for me..)
erissian
erissian
How about directinput?
CreateDevice(GUID_SysMouse,&mouse,NULL);
mouse->Acquire();

Test periodically. If it fails, then no mouse.
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.