How does it work? It cheats, that's how!

by Michael S. Kaplan, published on 2008/06/27 10:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2008/06/27/8661641.aspx


The question developer Cynthia sent via the Contact link was a fun one:

How can I program the "Fn" key on my laptop keyboard via MSKLC?

The answer is that you really can't.

Because the Fn or Function key has a very special job -- its job is to cheat.

Laptop keyboards are smaller, and they have fewer keys on them than they claim to. They get away with that by having a key that can transform other keys, temporarily changing their identity!

I'll show you what I mean....

First we'll go to my Dell, taking that EXE from Handling [Unicode] input in the console to sniff out the keys like I mentioned earlier today.

I'll type some keys that are on the keyboard and identify them right here so you can see what that EXE tells us. It tells us nothing about the Fn key -- that key does not exist as far as Windows is concerned:

ReadConsoleInput test
Ctrl-D to quit.

#      UC    u/d  VK   SC  State

  0: U+0000 down 0025 004b 0100    <-- Left Arrow  (VK_LEFT)
  1: U+0000  up  0025 004b 0100
  2: U+0000 down 0026 0048 0100    <-- Up Arrow  (VK_UP)
  3: U+0000  up  0026 0048 0100
  4: U+0000 down 0027 004d 0100    <-- Right Arrow  (VK_RIGHT)
  5: U+0000  up  0027 004d 0100
  6: U+0000 down 0028 0050 0100    <-- Down Arrow  (VK_DOWN)
  7: U+0000  up  0028 0050 0100
  8: U+0000 down 0024 0047 0100    <-- Home  (VK_HOME)
  9: U+0000  up  0024 0047 0100
 10: U+0000 down 0021 0049 0100    <-- Page Up  (VK_PRIOR)
 11: U+0000  up  0021 0049 0100
 12: U+0000 down 0023 004f 0100    <-- End  (VK_END)
 13: U+0000  up  0023 004f 0100
 14: U+0000 down 0022 0051 0100    <-- Page Down  (VK_NEXT)
 15: U+0000  up  0022 0051 0100
 16: U+0008 down 0008 000e 0000    <-- Backspace  (VK_BACK)
 17: U+0008  up  0008 000e 0000
 18: U+0000 down 002e 0053 0100    <-- Delete  (VK_DELETE)
 19: U+0000  up  002e 0053 0100

Now of these 10 keys, note that half of them do not exist as dedicated keys on my MacBook Pro.

What's a guy who likes his Mac to do?

No worries, because I can use my Fn key!

Here is the same output on the Mac Book Pro (booted into Vista 64 bit and humming along quite happily):

ReadConsoleInput test
Ctrl-D to quit.

#      UC    u/d  VK   SC  State

  0: U+0000 down 0025 004b 0100    <-- Left Arrow  (VK_LEFT)
  1: U+0000  up  0025 004b 0100
  2: U+0000 down 0026 0048 0100    <-- Up Arrow  (VK_UP)
  3: U+0000  up  0026 0048 0100
  4: U+0000 down 0027 004d 0100    <-- Right Arrow  (VK_RIGHT)
  5: U+0000  up  0027 004d 0100
  6: U+0000 down 0028 0050 0100    <-- Down Arrow  (VK_DOWN)
  7: U+0000  up  0028 0050 0100
  8: U+0000 down 0024 0047 0100    <-- Fn + Left Arrow  (VK_HOME)
  9: U+0000  up  0024 0047 0100
 10: U+0000 down 0021 0049 0100    <-- Fn + Up Arrow  (VK_PRIOR)
 11: U+0000  up  0021 0049 0100
 12: U+0000 down 0023 004f 0100    <-- Fn + Right Arrow  (VK_END)
 13: U+0000  up  0023 004f 0100
 14: U+0000 down 0022 0051 0100    <-- Fn + Down Arrow  (VK_NEXT)
 15: U+0000  up  0022 0051 0100
 16: U+0008 down 0008 000e 0000    <-- Backspace (Delete)  (VK_BACK)
 17: U+0008  up  0008 000e 0000
 18: U+0000 down 002e 0053 0100    <-- Fn + Backspace (Delete)  (VK_DELETE)
 19: U+0000  up  002e 0053 0100

Pretty clever, huh? even though Windows can't see the Fn key, the keyboard can. And the hardware can fake out and make Windows think that one key is another, as needed.

As far as Windows knows, that key identity is indistinguishable from it being that totally different key....

Now if they could just use the Fn key to fix up the whole  | (U+007c, a.k.a. VERTICAL LINE) yet printed upon the face of the key is ¦ (U+00a6, a.k.a. BROKEN BAR) issue!

 

This post brought to you by ¦ (U+00a6, a.k.a. VERTICAL LINE)


Programmerman on 27 Jun 2008 2:19 PM:

I've scoped out my three keyboards and they're two-for-three on having it right (two vertical lines, one broken bar).

Zooba on 27 Jun 2008 7:42 PM:

Wow. A sponsor with a split personality (or who has committed identify theft). Very appropriate :-)

Michael S. Kaplan on 27 Jun 2008 7:50 PM:

I was wondering who was going to notice that one and how long before anyone said anything! :-)

Maurits [MSFT] on 27 Jun 2008 9:03 PM:

I suppose one could argue that the "solid" bar looks too much like a capital "I" in the font used to physically keyboards.

Mike Dimmick on 30 Jun 2008 6:25 AM:

My Dell UK keyboard has | in the lower-left, as shift+\, while it has ¦ marked as the AltGr+` state (the UK keyboard has ¬ as shift+`).

The console 8 wide/12 high raster font on Windows XP shows ¦ for both codepoints. The other raster fonts appear to be similarly afflicted.

Putting the command prompt in full-screen mode, in CP 850 the glyphs produced are correct; in 437 the ¦ key-chord produces a blob (one of the line-drawing characters, perhaps?)

However, in DOS 6.22 with the UK keyboard installed and codepage 850 selected, the characters are swapped, which I think matches what used to be inscribed on the keys. I think a lot of UK DOS users used CP437, though, as that was the default. I don't recall having to press AltGr+` to get a 'pipe' to pipe output from one command into another. Tested in Virtual PC 2007 SP1 (with older Additions as the VPC team seem to have encoded the Additions ISO with lower-case characters in filenames, which DOS has a problem with!)


go to newer or older post, or back to index or month or day