May 4th, 2016

How can I detect whether the user’s keyboard has a Break key?

Some time ago, a customer wanted to know whether there was a way to detect whether or not the user’s keyboard has a Break key. “Our program has a hotkey that involves the Break key. Nowadays, the trend in laptop keyboards is to remove the Break key, which leaves users no way to invoke the hotkey. We want to offer an alternate hotkey, but only if the user’s keyboard doesn’t have a Break key.”

The device driver people explained that the driver has no idea what physical keys are present on the keyboard. So there’s no way to know whether a Break key exists, except by inferring the presence of such a key if you ever see a report that says “Hey, the user hit the Break key.”

That answers the technical problem: No, there is no way to know whether the keyboard has a physical Break key, or at least no way at the driver level to know.

But even if it were possible, from a user experience point of view, you don’t want to change the hotkey based on whether the keyboard has a Break key. For one thing, it forces the user to remember additional state: They have to use one hotkey when at their desktop PC, and another hotkey when using their laptop.

The user may have a Bluetooth keyboard paired to the laptop, even though they are actively using the integrated keyboard. If the Bluetooth keyboard has a Break key, the program would require the user to use the Break hotkey, even though the laptop keyboard doesn’t have a Break key.

If the user is on the edge of Bluetooth range, that Bluetooth keyboard may come and go randomly, at which point the application hotkey changes randomly.

And changing the hotkey based on the keyboard the user typed on most recently is even more crazy.

The customer accepted our explanation that there is no way at the driver level to detect what types of keys are available on the current keyboard, and that even if you knew, you probably shouldn’t act on it. Best would be to leave both sets of hotkeys active at all times.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.