-
Checking for devices...
I'm using Dev-C++ 4.9.9.1 on Windows XP Home Edition, and I am wondering if there is a way to see if the mouse and the keyboard are plugged into the computer. Like:
Code:
if( !MousePluggedIn )
{
std::cout << "No mouse!";
}
else if( !KeyboardPluggedIn )
{
std::cout << "No keyboard!";
}
or something along those lines. Thanks.
- SirCrono6
-
#include<windows.h>
I can't find anything to determine if a keyboard is available, but I can answer your mouse question.
Using Win32API, you can determine if the mouse is available by:
Code:
fMouse = GetSystemMetrics(SM_MOUSEPRESENT);
The value of fMouse will be TRUE (nonzero) if a mouse is installed and 0 if mouse is not installed.
(However in Windows 98 this functions always returns TRUE whether a mouse is attached or not)
To determine the number of mouse buttons:
Code:
cButtons = GetSystemMetrics(SM_CMOUSEBUTTONS);
-
According to MSDN, GetSystemMetrics( SM_MOUSEPRESENT ) returns non-zero if there is a mouse installed and zero if there isn't. I tested this: mouse in was true and mouse out was true. This seems to be because the mouse is installed whether or not it is plugged into the computer. Thanks anyways :)
- SirCrono6