is there any way to retrive ASCII character from WM_KEYDOWN message but not using TranslateMessage() function

Posted on 2002-05-03 16:41:03 by Mikky
The doc's are rather convoluted on this topic, i know, cause i scoured through them a few days ago.

Turns out you got them already mapped when you get the message.

The wparam is the VK_XXXX of what ever char your looking for. Almost all are 1:1 (ASCII Char:VK_Char), so with some exception to the the non-standard keys you can use the VK_XXX code.

Look up the chars of interest in the MSDN page:


( Keep the link, its a hard one to dig up )

Hope it helps.
Posted on 2002-05-03 21:19:06 by NaN
BTW: I also process the WM_CHAR message, which *is* the actuall ascii codes.

The WM_KEYDOWN is sent before the WM_CHAR message, but both do get sent if normal chars. Things like shift keys only get the WM_KEYDOWN message, there is no ascii CHAR for this.

So i recomend you process both for your app's uses.

Posted on 2002-05-03 21:22:06 by NaN
The idea was to avoid using TranslateMessage which generates the WM_CHAR message.

As NaN mentions, the virtual keycodes can be used ( and the link is pure goodness, all the keycodes are listed :) ).

When processing the WM_KEYDOWN message the virtual keycode is in wParam

An example ..

mov eax,wParam
.IF eax==VK_A
; the A key has been pressed


- edited a few typos, forgot some capital letters here and there.
Posted on 2002-05-04 07:13:33 by Flyke
ok well acctually what i need is to get ascii char, not key pressed
in ascii "A" is different than "a" while virtual keys are the same
Posted on 2002-05-04 09:30:20 by Mikky
Right, the WM_CHAR message will send you this distinction.

If you press 'A' you get 0x41h , if you press 'a' you get 0x61h

If you press either, you also get a WM_KEYDOWN message with VK_A in the wParam.

Handle both messages to do whatever you want. (( But for just letters and #'s you dont need the WM_KEYDOWN message at all ~ like i said, its advantage is for stuff like F1, F2, Cursors, etc. ))

Posted on 2002-05-04 11:43:51 by NaN
well yes i know all that but i think you didnt understand me well what actually want

and what i want is to get the ascii code of character from WM_KEYDOWN message without using TranslateMessage() function if that is possible anyhow

this is becouse my program doesnt have window so it recive messages from another program by PostThreadMessage() and thus i need to process messages directly in infinite loop

my loop looks like this

.while 1
invoke GetMessage, addr msg, 0, 0, 0
.if msg.message == WM_KEYDOWN
; retrive character input here
; if character pressed == A do somthing
; if character pressed == a do somthing else
.if msg.message == WM_USER+100 ; my custom message for quit
. break

i hope this clears things up
Posted on 2002-05-04 12:42:55 by Mikky
You got me here, i dunno why you cant send the WM_CHAR to the private thread, if your already passing along the WM_KEYDOWN message anyways. ??? :confused: ???
Posted on 2002-05-04 17:00:02 by NaN
well this thread in another process, so my program recives messages from other processes
anyway i think i have a solution
i can use virtual keys (in wParam of WM_KEYDOWN) becouse they have same values as ascii codes so only problem is to determine which character key is pressed capital (A) or noncapital (a)
i can to that with GetKeyState() function to check if caps lock is toggled on or shift was pressed etc
if ether is pressed the key is capital if both or nether is pressed the key is non capital
Posted on 2002-05-04 17:06:15 by Mikky
While you are at it could you tell me if it's possible to process WM_KEYDOWN or WM_CHAR message sent to edit control, within dlg procedure loop (invoked with DialogBoxParam), it doesn't seem to work? The main window is a dialog window.
Posted on 2002-05-04 18:53:19 by ramzez
Getting the ascii code from WM_KEYDOWN is not possible unless you check for upper/lower case yourself.

In WM_KEYDOWN there is no distinction between 'a' and 'A'.

Guess you already knew this :)

Posted on 2002-05-04 19:09:05 by Flyke

    [*]Get the ID of the Edit Control on the Dialog box
    [*]Get Handle from Dialog ID and save it
    [*]Call GetWindowLong, for WINDOWS (edit control == window), and subclass the control to a new WndProc.
    [*]In the new WndProc, pass all messages along to the old proc, but also 'Spy' on the WM_CHAR and WM_KEYDOWN messages being sent to it.
    [*]From here, send messages back to your main window as a WM_USER + xxx custom message to indicate you got a char or what not.

    I would be hesitant to sent WM_CHAR or WM_KEYDOWN itself, as you never know what the message translator might do if its not a *true* message.

    Hope it helps..
Posted on 2002-05-04 19:29:43 by NaN