Program to check mouse and keyboard

Dell GX260 Optiplex
January 19, 2007 at 08:42:50
Specs: Windows XP SP 2, Pentium 4 2.26 GHz/512 MB

My company has some Windows XP client PCs on which a batch file regularly runs and writes information about the PC to a NAS drive. We want to add the following information to the output:

* Whether a keyboard and mouse are connected.
* If connected, whether the keyboard and mouse are working properly.

Does anyone know how a program can interrogate Windows XP to get that information? We want to use one of the following technologies:
* Functions, command line utilities, or scripting languages that are included as part of XP.
* Alternatively, a C program.

We are reluctant to use other technologies if it can be achieved with one of the above, because we are already using only C for bespoke programs on these clients and prefer not to force the support team to support new languages.


See More: Program to check mouse and keyboard

Report •


#1
January 20, 2007 at 02:23:44

By interrogating the system you can detect the presence or absence of a mouse or keyboard. But the is no way you can check 100% functionality without actually moving the mouse and using the keyboard.

Report •

#2
January 22, 2007 at 02:31:49

Being able to check for presence only is still a big improvement on what we have now. Does anyone know the names of suitable functions to make the checks, or have a code example? I have searched online to try to find exactly what I need, but the only example I found was for VB.

Report •

#3
January 22, 2007 at 03:55:51

Some progress...
User32.dll contains the API GetKeyboardType. On my setup, this returns 4 (i.e. detects IBM enhanced 101- or 102-key keyboard). When I unplug the keyboard and then rerun the code to call GetKeyboardType, it continues to return 4. i.e. it doesn’t automatically detect that there is no longer a keyboard plugged in.
If I rebooted with no keyboard and called the function again, I would expect it to return the error code (0) to say there is no keyboard. I can’t test this at work because I can’t get past the login screen without a keyboard!

Report •

Related Solutions

#4
January 22, 2007 at 05:17:59

The User32.dll call GetSystemMetrics (SM_MOUSEPRESENT) has the same type of problem. It fails to detect when the mouse has been removed within an XP session. Worse still, even if I unplug the mouse and reboot, the above call still detects a mouse as being present.
It may be that the solution must be more intricate than either of the 2 simple API calls tried so far. Any ideas?

Report •

#5
January 22, 2007 at 17:23:39

Paul,

What I think you've noticed is Windows inherit ability to give you completely worthless information simply because a driver is installed. "If the driver is there, who cares about the device!"

I would think (stress _think_) that API calls would prove pretty much useless as you have discovered so far. Unfortunately, as WizardFred suggests, I'm not sure you can actually tell if the keyboard is plugged in without some kind of key logger...which could then produce false alarms.

Might not be much, but here's a thought: what happens if you try to set NumLock through the API and then read its value back? If there is no keyboard attached, would NumLock toggle? Just a thought.

Good luck (and I'll try to think of more ideas),


Stephen


"Live long and PROGRAM......or at least do _something_ with all that time...!"


Report •

#6
February 2, 2007 at 08:40:25

The answer is: the requirement is not realistically achievable. The extract below from my design document explains why. It doesn't mention wireless mice, which are another point illustrating the complexity of trying to do this:

=======================================
There is no reliable way to check whether a mouse is physically connected to a computer. The Windows APIs will always return a value indicating a mouse is connected whenever a mouse device driver is installed; whether or not a mouse is physically connected at the time of the API call is irrelevant. Windows XP includes the MouseKeys accessibility feature, based on a ‘virtual mouse’ that will always be detected by, for example, the MyComputer.Mouse.Exists property of VB.NET.

It is theoretically possible to check whether a PS/2 keyboard is connected to a computer (a port in the status register contains a flag indicating this). However, such ports cannot be directly accessed from Windows; device drivers or third party libraries would need to be investigated to achieve this. There is the potential for a mixture of USB and PS/2 keyboards to be deployed across the suite of kiosks. An additional complication is wireless hardware; it might be the case that such hardware will become widely used within the company in the future, requiring maintenance of the delivered solution. In summary, the business benefit of automatically being alerted that there is no keyboard connected to an kiosk is outweighed by the difficulties in trying to devise a solution that will run on Windows and be compatible with all types of keyboard used within the company.

A more reliable solution may be physically secure hardware, which is outside of scope. Any missing peripherals will have to be manually reported by users at adjacent kiosks.
=======================================


Report •


Ask Question