ASCII characters entered using ALT+<Numpad> in a Textbox

ASCII characters entered using ALT+<Numpad> in a Textbox

Post by TWF0aGlhcy » Tue, 01 Apr 2008 21:06:00


Hi,

I have a TextBox control in a WinForms dialog. If I enter a Character and
convert it to ASCII by ASCIIEnconding.ASCII.GetBytes() it works. But when I
enter an ASCII value below 0x20 by holding ALT and entering the value using
the number pad I get and convert it, I do not get the correct value.

For example: ALT+25 shows a Down-Arrow in the box, gets 0x2193 in the
KeyPressEvent.KeyChar and is converted to 0x3f by
ASCIIEnconding.ASCII.GetBytes(). I would expect 0x19 for decimal 25.

Has anyone an idea how to get the correct value?

Thanks in advance,
Mathias
 
 
 

ASCII characters entered using ALT+<Numpad> in a Textbox

Post by Jeff Johns » Thu, 10 Apr 2008 00:07:01

"Mathias Zuckermann" <Mathias XXXX@XXXXX.COM > wrote in



I'm no expert, but I believe this behavior demonstrates a clash between the
legacy days of DOS and the modern world of Unicode. There's probably
something happening at a very low level (keyboard driver, I'd guess) in
Windows that maps these low-ASCII values to the corresponding symbol in
whatever Unicode subrange it now lives in. (In ye olden days we'd call this
the OEM section.)

Ultimately, I doubt you're going to be able to determine what key sequence
was pressed without building a lookup table of your own and checking it.
Hopefully I'm wrong and someone will post a cleaner solution.