'scan code' & 'ASCII code' from keyboard

Hi all,

I wrote a filter driver for keyboard and it reads so called ‘the scan code associated with a key press’.

KeyData = Irp->AssociatedIrp.SystemBuffer ;
USHORT Code = KeyData.MakeCode ;

Now, I want to know, what letter ASCII is associate with a key press. For example:
If I press ‘A’ (on the keyboard), ‘scan code’ = 1e, I want to know that letter ASCII is ‘41’ (A)
If I press ‘S’ (on the keyboard), ‘scan code’ = 1f, I want to know that letter ASCII is ‘53’ (S) ETC.

Grand merci for every help - THX
It greeting from Polish

This is the data in the keyboard layout DLLs in the simple case, and in
executable code in some complex cases, not to mention the IMEs in the Asian
case.

Ah Benson said, there is no simple solution for most of the keys.
But still you can get much information and a table on :
http://www.microsoft.com/whdc/hwdev/tech/input/w2kscan-map.mspx
but this document talks more about physical layout and not about keyboard language setup or IME.

Depending of what you want to do, you can look at high-level or low-level user-mode filtering.
SetWindowsHookEx(WH_KEYBOARD_LL, …) but still it cause context switches on each keypress which may be undesirable and still doesn’t gives WM_CHAR and WM_UNICHAR, since it is done in TranslateMessage().

In fact, the scancode -=> unicode char is done in usermode per process context so there is no exact way to do this in KM.

If you do your driver just for fun, hardcode the key tables. Otherwise, good luck.

De rien!
M-A

-----Original Message-----
From: Marcin O. [mailto:xxxxx@poczta.fm]
Sent: 22 juillet, 2003 08:24
To: Windows System Software Developers Interest List
Subject: [ntdev] ‘scan code’ & ‘ASCII code’ from keyboard

Hi all,

I wrote a filter driver for keyboard and it reads so called ‘the scan code associated with a key press’.

KeyData = Irp->AssociatedIrp.SystemBuffer ;
USHORT Code = KeyData.MakeCode ;

Now, I want to know, what letter ASCII is associate with a key press. For example:
If I press ‘A’ (on the keyboard), ‘scan code’ = 1e, I want to know that letter ASCII is ‘41’ (A)
If I press ‘S’ (on the keyboard), ‘scan code’ = 1f, I want to know that letter ASCII is ‘53’ (S) ETC.

Grand merci for every help - THX
It greeting from Polish

Windows does this conversion in user mode only (in TranslateMessage), and the
conversion depends on NLS support and current keyboard layout. I don’t think
you can do this in kernel mode.

Max

----- Original Message -----
From: “Marcin O.”
To: “Windows System Software Developers Interest List”
Sent: Tuesday, July 22, 2003 4:23 PM
Subject: [ntdev] ‘scan code’ & ‘ASCII code’ from keyboard

> Hi all,
>
> I wrote a filter driver for keyboard and it reads so called ‘the scan
code associated with a key press’.
>
> KeyData = Irp->AssociatedIrp.SystemBuffer ;
> USHORT Code = KeyData.MakeCode ;
>
> Now, I want to know, what letter ASCII is associate with a key press. For
example:
> If I press ‘A’ (on the keyboard), ‘scan code’ = 1e, I want to know that
letter ASCII is ‘41’ (A)
> If I press ‘S’ (on the keyboard), ‘scan code’ = 1f, I want to know that
letter ASCII is ‘53’ (S) ETC.
>
> Grand merci for every help - THX
> It greeting from Polish
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>