Hacking the Natural 4000 keyboard

There have been a lot of blog posts around the internet about how to fix or change the “zoom” feature on the Microsoft Natural Ergonomic Keyboard 4000 into a scroll up/down feature instead — my favorite is this one by Olivier Dagenais which suggested using an XSL transform.

However, nobody seems to have fixed the F-Lock problem … so I started digging into the command mapping to see what I could figure out. I’ve got a fix posted at the bottom, so if you don’t care how this works, just skip to the end. I’m working on a Natural Ergonomic 4000, but some of what I found should apply to any keyboard using Microsoft’s IntelliType software. What we all know by now is that it has xml-based command remapping. The definitions for the remapping are in a file called commands.xml in the install directory, which is, by default: “C:\Program Files\Microsoft IntelliType Pro”.

There’s two interesting things happening in the IntelliType software. First, the “My Favorites” buttons on the Natural 4000 don’t seem to be a part of this remapping scheme. Second, although all of the remapping can be done in the commands.xml file, the control panel (at least in Vista) doesn’t use the commands.xml file at all — it adds entries to the registry!

The Registry Keys

The mappings from the control panel happen in this key: HKEY_CURRENT_USER\Software\Microsoft\IntelliType Pro\EventMapping and I’ll list the subkeys off here really quick:

  • 14 is the back button
  • 15 is the forward button
  • 18 is the search button
  • 20 is the Web/Home button
  • 21 is the Mail button
  • 25 is the Play/Pause button
  • 31 is the Calculator button
  • 42 is the F1 key
  • 54 is the F2 key
  • 55 is the F3 key
  • 45 is the F4 key
  • 46 is the F5 key
  • 47 is the F6 key
  • 48 is the F7 key
  • 49 is the F8 key
  • 50 is the F9 key
  • 51 is the F10 key
  • 52 is the F11 key
  • 53 is the F12 key
  • 78 is the First Favorite Apps button
  • 79 is the Second Favorite Apps button
  • 80 is the Third Favorite Apps button
  • 81 is the Fourth Favorite Apps button
  • 82 is the Fifth Favorite Apps button
  • 73, 74, 75, and 83 are the Left Win, Apps, CapsLock, and Volume keys which can’t be remapped via Intellitype, but can only be disabled.

I’ll add some more information here later about the possible contents of these keys, but the most important thing is this: the Command value dictates what the button does There is also a “ShellExecute” value which has a file path or URL that can be launched if the Command is set to 800 (decimal). The possible values for Command are basically all the different built-in commands — which are listed in the mscmdkey.xml file.

The Commands

The weird thing is that some of the commands in mscmdkey don’t make sense as commands (like RSSI_NOISE_COMMAND or BATTERY_CRITICAL_COMMAND). Additionally, some of them can’t actually be used (you can’t remap F1 to “313” which is the left window key). I’ll mostly let you read the commands for yourself from that file. A couple of them are worth giving more detail about:

  • 0 is the “invalid” command which disables the key
  • 2 is the special “unassigned” command (the 5 favorites buttons start as this by default, but you can set any of the other settable buttons to this, which would result in getting a prompt when you use it — I do this for the web/home, search, mail, and calculator buttons for other people’s accounts, so they can set them themselves also).
  • 800 is the “Shell Execute” command (which causes the value in ShellExecute to run).
  • 316 and 306 are the “Lock Workstation” and “Log Off” commands which are quite amusing to set on all of the keys as an April Fool’s joke.

Commands.xml Structure

The real power of the IntelliType system is the Commands.xml file. Unlike the registry settings, which are restricted to remapping the keys from one “command” to another, the Commands.xml file can actually create simple macros. Commands.xml consists of a root node DPGCmd which contains the copyright and version nodes, and a series of language nodes. The most important language node is the global “ALL” language. The “ALL” language contains mappings which are applied on top of whichever language you have your keys set to, and you should be aware of it whenever you’re doing remapping because if you map the same character twice in the same section (eg: for the same app) it will crash the IntelliType driver, even if the mappings are in your language section (eg: ENG for english) and the ALL section. If you only ever use a single language on your keyboard, the simplest thing to do is to just get rid of all the other nodes in the file to avoid these conflicts.

Each Language (including ALL) has a series of APPLICATION tags with per-application key maps. This is actually a very cool feature, except for the fact that they remapped keys like F5 and F3 which already have functions in most apps! At any rate, the key maps are defined as tag like: where the tag name is a C followed by the command number from mscmdkey.xml as mentioned earlier, which identifies the key. There are several possible attributes, but which ones are relevant depends on the Type attribute, which defines the type of remapping — depending on the type, there are additional parameters:

  • Type 0 – The simplest remapping, just disables the key.
  • Type 6 – Simple on the surface, this just takes an Activator command like “ZoomOut” or “ZoomIn” and “ScrollUp” or “ScrollDown”. The commands seem to be the ones defined in mscmdkey, but in PascalCase, instead of having underscores, and without the trailing “_COMMAND” text …
  • Type 5 – is obviously the most useful, because it lets you specify a key sequence like: which specifies keys to press. It appears that you can use the pipe character “|” to separate chords, so for instance “alt f | s” to press alt+f and then press s (eg: open the file menu and hit save). Certain key sequences cause problems, and there seems to be a limit to how many sequences you’re allowed (only 3?) I don’t know the full syntax here.
  • Types 1-4 seem to be for sending window messages, but it’s not clear how they work exactly, since 1 and 3 both take only a wParam, 2 takes only a lParam, and 4 takes both.
  • Type 7 – I really don’t know about. It takes a “subtype” which is one of the types listed above, and then, whatever additional parameter that type would take … but I’ve only seen it used for the 1003 command, which as far as I can tell is probably the Office Task Pane command, and is only used in MS Office apps (not to mention that a physical button for this doesn’t exist on any keyboards I’ve used).

The Most Interesting Keys

Each of the function keys map to a special command when the F-Lock mode is on … (you know them, because they’re labeled appropriately). For instance, the “Help” command, which is the F1 key, is command 302, so it appears in the commands.xml as <C302 ... />. The other interesting key, to me, is the scroll wheel, which turns out to behave somewhat like a key with variable-speed repeat. I’ve listed them below with the key they map to when F-Lock is engaged:

  • 319 Zoom In (we’ll remap this to Scroll Up, for lack of something more interesting)
  • 320 Zoom Out (we’ll remap this to Scroll Down)
  • 302 F1
  • 203 F2
  • 204 F3
  • 307 F4
  • 308 F5
  • 309 F6
  • 900 F7
  • 901 F8
  • 902 F9
  • 401 F10
  • 311 F11
  • 310 F12

The download

Having said all of that … the simplest thing to do is to just delete the whole EventMapping key and remap the F1-F12 keys in the commands.xml using an XSL style sheet like the one Olivier suggested. So, heter’s my IntelliType Fix – Right-Click and “Save As” to download it, and then apply it to your Commands.xml file. If you don’t know how to use an Xsl file, you could use my Xslt PowerShell script and make a backup copy of your commands.xml called commands.xml.old and run this, in PowerShell:

Convert-WithXslt `
    "$($env:ProgramFiles)\Microsoft IntelliType Pro\commands.xml.old" `
    IntelliTypeFix.xsl `
    "$($env:ProgramFiles)\Microsoft IntelliType Pro\commands.xml"
kill -name itype
&"$($env:ProgramFiles)\Microsoft IntelliType Pro\itype.exe"

Similar Posts:

    None Found

4 thoughts on “Hacking the Natural 4000 keyboard”

  1. Thanks for this information since I’m annoyed with the limitations in the IntelliType software. Between this information and some information on the Autohotkey site I was able to remap all my special keys on this keyboard to do whatever I want using the well-documented and feature-filled autohotkey software (rather than the limited intellitype software).

    In case it’s of use to anyone else, here’s what I did.

    You can create scripts directly using Autohotkey for any of the key codes that it can pick up. Use its instructions to discover the key codes for the special buttons and then set these keys to “disabled” in the intellitype software control panel so you can work with them directly with Autohotkey.

    Unfortunately, the favorites 1-5 and the help, undo, etc (alternate F1-F12) keys don’t send any special keycodes that Autohotkey can recognize. To send these keys to Autohotkey you need to do what you describe here and remap the keys in the IntelliType configuration files and registry to send keystrokes which Autohotkey can then pick up. For example, I’m having the Help (F1) key send ALT-CTRL-SHIFT-F1 from the IntelliType software which Autohotkey can pick up and do something more useful with.

    I ran into the issue of almost not having enough of the Microsoft command numbers to remap all the keys that Autohotkey couldn’t pick up. As you noted, some actions like “logoff” will still take their action no matter how you remap them with the commands.xml file. The command ids I used that seemed (mostly) to work globally without undesired side-effects were 100, 101, 102, 103, 200, 201, 202, 203, 204, 301, 302, 307, 308, 309, 310, 311, 315. I deleted most of the application-specific actions from the commands.xml file and just left the “StandardSupport” section and an empty language section for English.

    Removing application-specific settings isn’t a problem since autohotkey can also map keys differently depending on the application or active window if you want the keys to act differently in different applications.

    I ran into problems with the ids 100-103. They would fire from IntelliType when a window was active, but the keys didn’t seem to fire when I was hovering the mouse over an icon on my desktop, for example.

    I fixed the problem of special circumstance IntelliType keys by editing the mscmdkey.xml file and changing appCommand=‘36’ for each of these items. This appCommand number originally went with the copy command, but IntelliType didn’t care that some other items in mscmdkey.xml also used this appCommand too. It successfully changed the behavior so the key acted globally rather than just in a specific circumstance or window.

    I’m thinking that perhaps some of the keys that don’t remap well to other behaviors might be able to be remapped to do standard key combinations by changing their appCommand number to 36 or one of the appCommands that doesn’t take any specialized action. Maybe it would be possible to use the commands such as “logoff” to do other things if you change their appCommands in mscmdkey.xml. I suspect the appCommand number references an action elsewhere (perhaps in one of those dlls) and the more extreme actions could be neutered by changing their appCommands to something else.

    I hope this is helpful to someone out there.

  2. Hey Scott,

    Thanks for sharing the tips.
    Although when I got that keyboard I quickly hacked into commands.xml, I never understood why some keys kept some functions.
    Now I know I have to modify mscmdkey.xml too.
    Funnily I am an AHK user too. Now thanks to you I can use Browser_back and Browser_forward (C101 & C100) for working with my WIP scripts. I usually set one of them to save the script, reload and winactivate the window I want the script to act on and the other to go back to the editor I use for the script. Very convenient.

    I think I didn’t see those explanations on the AHK forums, although there are some MS NK4000-related threads. Might be a good idea to post a copy there for others.

  3. Hello, I’ve read this post. I’ve the same keyboard, and I want to remap the favorite keys to do what a normal key do (letter, f1-f12, isn’t important), because I want to use them in a program who can recognize only standard keys…anyway, I’ve don’t understand what I’ve to write to remap these particular buttons… someone can explain it better? I’ve understood that Scoot does it, but how? O_o

Comments are closed.