Web Rarely

No group of professionals meets except to conspire against the public at large. -- Mark Twain

it's good to be a hacker

2008-08-03

A while ago, the backspace key on my laptop keyboard stopped working. If this had been a regular keyboard, I would have just taken it apart and cleaned or fixed whatever was the problem. But things are never so simple with laptops. The keyboard couldn't be removed except by disassembling the entire laptop. And I'm far too lazy for that. So for months I was going without a backspace key, which is of course a pain.

Then I got the brilliant idea of modifying my keyboard drivers to remap some rarely-used key to backspace. The only keys that I don't really use are Pause/Break and Num Lock. But it turns out that those two keys happen to be involved in some awful backwards compatibility mess. You see, in the old days, it was much cheaper and easier to make keyboards that mapped keys by position rather than by the actual meaning of the key, and then do the mapping from key position to key meaning in software. These positions codes are called scan codes, and are keyboard-specific. Every model keyboard can potentially have a completely different mapping of scan code to key meaning.

To make things even messier, scan codes can be variable-length, and special scan codes (typically E0, E1, and E2) can modify the meaning of the following scan code sequence. Now, I wanted to remap the Pause/Break key. Due to some historical idiocy, it turns out that keyboards transmit the Pause/Break key with the sequence "E1, LeftCtrl, NumLock". That is, rather than having its own unique scan code, the Pause/Break key is formed by combining the scan codes for the left Control key and the Num Lock key. As far as I know, it's the only key that works like that.

I don't think Windows keyboard layouts are capable of handling this oddity directly, so as a result Windows seems to contain a hack that converts the sequence "E1, LeftCtrl" into the pause/break key, and then ignores the Num Lock key that follows. In typical Microsoft style, none of this is documented.

So what happened was that when I pressed Pause/Break, it would indeed work as a backspace key, but then Windows would no longer ignore the Num Lock key that followed, so pressing my new backspace key would also toggle the numpad, which is an awful thing on a laptop. It took a while to figure out why. Finally I gave up on that and just remapped Num Lock to backspace, and Scroll Lock to Num Lock. And it works!

In retrospect, I suppose I could have just hijacked the Caps Lock key instead and avoided the whole mess.

It's nice to be able to do this kind of thing. It's a whole lot better than sending the laptop to Dell, paying them $100 to fix the keyboard, and having them mistakenly format my hard drive instead.

Comments

dude.. 2008-08-12 03:05AM
I can't believe you're mapping the numlock key, that will take forever to get used to.. On my laptop, I have to press the function key to do that so it'd be a real pain ;-). Anyways, you can get a replacement laptop keyboard for less than $20 shipped on Ebay.. sure, replacing it youself probably voids your warranty, not that you have any left or probably trust them to use it anyways.. but from what I remember, keyboard replacement is pretty straightforward. Or just use an external keyboard, there are piles and piles of them in a giant box in the building 16 garage.
an anonymous Bryant
ok.. 2008-08-12 03:06AM
ok, so how do I become a "non-anonymous" Bryant, and how do I not expose my e-mail address?
an anonymous Bry
re: ok.. 2008-08-12 07:47PM
Thankfully on my keyboard, I don't have to press the function key to toggle the NumLock. I've got an external keyboard, but there's nowhere to put it that's as comfortable as the built-in one. :-P

To become a non-anonymous Bryant, you can create an account. To not expose your email address, don't enter it. It's not required. Would you like me to erase the email address that's already been entered so spammers don't harvest it? :-)

Add a comment

Note: The information you enter (including your name and email address) will be displayed publicly.




Line breaks are converted to <br>'s, and all HTML tags except b, u, i, tt, and pre are filtered out.