4

I am getting text input and keypress input from the WM_CHAR and WM_KEYDOWN messages

What I want to do is filter out WM_CHAR messages the have the same VK_ code as the key that is bound to enable the control that you enter text in.

EG: Game uses ~ to enable console, key binding is done via VK_OEM3 and WM_KEYDOWN, but text input into the console needs text from WM_CHAR.

As the WM_KEYDOWN happens first, the console is activated, then a WM_CHAR of ~ is sent to the console buffer which I don't want.

I figured the best way to prevent this is to compare the VK_ from the WM_CHAR to the bound key for the control and filter it out.

Is there a way to get the VK_ from a WM_CHAR message?

I read that you can get the scancode out of Lparam at bits 16-23

But am unsure how to:

  1. Extract the value of the scancode from lparam
  2. Translate the scan code to a VK_ correctly
0

3 Answers 3

5

After some messing around I managed to extract the virtual key with the following code:

This code gets the address of lParam as a unsigned char array (one byte of length), then uses pointer arithmatic to address the 3rd byte (bits 16-23):

 unsigned char scancode = ((unsigned char*)&lParam)[2]; 

This code translates from the scancode to the virtual key:

 unsigned int virtualKey = MapVirtualKey(scancode,MAPVK_VSC_TO_VK); 
Sign up to request clarification or add additional context in comments.

Comments

2

Perhaps you migh use MapVirtualKey.

I am not sure how to extract scancode from lparam as documentation does not state that - either get entire lparam and count that this function knows which bits to look at, or use bitfield struct and just get right bits out of it. I think on of those methods should work - trying both shouldn't be difficult.

Comments

0

Just compare scancodes:

case WM_KEYDOWN: case WM_KEYUP: case WM_SYSKEYDOWN: case WM_SYSKEYUP: case WM_CHAR: { WORD keyFlags = HIWORD(lParam); WORD scanCode = LOBYTE(keyFlags); // scan code if ((keyFlags & KF_EXTENDED) == KF_EXTENDED) // extended-key flag scanCode = MAKEWORD(scanCode, 0xE0); ... 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.