Problem catching numpad keystrokes

Nov 25, 2010 at 7:34am
Hello
Im wanting to use my numpad as direction north,east,south,west ect and have all other alpha/numbers work for text display.
So far i have experimented with wm-keydown and wm-char and found the later to be the best for handling the text output but its no good for catching the numpad keys as tranlatemessage converts them to the number vk codes.
I can catch the numpad entries with wm-keydown but then translatemessage sends it on to wm-char which is not what i want.
Is there a way to stop the key stroke being processed further after i have caught it in wm-keydown?.
Maybe im going about this all wrong, i have googled for the last few days on the subject with no luck.
I have been using wParam but wondering if i should be try lParam to better define what key was pressed.

Im using Dev-C++
Nov 25, 2010 at 11:09am
You need to check the message after calling GetMessage. Only call TranslateMessage if it's not one you want translated. That's how MFC implements PreTranslateMessage.
Nov 26, 2010 at 5:48am
Thank you kbw this is what i come up with

1
2
3
4
while (GetMessage (&messages, NULL, 0, 0) > 0)
    {
        if (DispatchMessage(&messages) != 1) TranslateMessage(&messages);
    }


All keystrokes successfully handled in WM_KEYDOWN return 1 and everything else is translated.

Nov 26, 2010 at 9:55am
I was thinking more (from memory):
1
2
3
4
5
6
7
8
9
while (GetMessage(&msg, 0, 0, 0))
{
    if (PreTranslateMessage(&msg))
    {
        TranslateMessage(&msg);
    }

    DispatchMessage(&msg);
}


Then you can put your check in PreTranslateMessage.
Last edited on Nov 26, 2010 at 9:57am
Topic archived. No new replies allowed.