# WM_INPUT with Arrow Keys Failing

This topic is 2011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys,

I'm not getting the response I expect from the arrow keys:

#define key_right 0x27
#define key_d 0x44

USHORT key=raw->data.keyboard.VKey;

// arrow key not working
if(key == key_right){
if(raw->data.keyboard.Flags == 0)
face_right=1;  // this line never triggers
else
face_right=0;
}

// but other keys (like the D key) work just fine

if(key == key_d){
if(raw->data.keyboard.Flags == 0)
face_right=1;
else
face_right=0;
}


##### Share on other sites

Does the debugger get triggered if you put a breakpoint on the line

USHORT key=raw->data.keyboard.VKey;

and press the arrow key? If so, what's the VKey value?

I never used rawinput, so i can't help you much. Just saying (i know, im an optimization freak ), you can replace

if(raw->data.keyboard.Flags == 0)
face_right=1;
else
face_right=0;


by

face_right = raw->data.keyboard.Flags == 0 ? 1 : 0;



And hum, you don't need to redefine those key, they're already defined as VK_RIGHT and VK_D respectively.

Edited by Vortez

##### Share on other sites

I never used rawinput, so i can't help you much. Just saying (i know, im an optimization freak ), you can replace

if(raw->data.keyboard.Flags == 0)
face_right=1;
else
face_right=0;


by

face_right = raw->data.keyboard.Flags == 0 ? 1 : 0;



The compiler should produce the same code for both, and the first is cleaner should you ever come to add a second action to each condition case.

##### Share on other sites
if(key == key_right){
if(raw->data.keyboard.Flags == 0)
face_right=1;  // breakpoint one : never triggers (on keydown or keyup)
else
face_right=0; // breakpoint two : always triggers on keydown but should only trigger on keyup
}


...so it's registering the right key properly, just not it's state.

PS - I was using the shorthand version but changed it to debug this problem.

##### Share on other sites

Did you pass the message on to DefWindowProc? If you don't some states may not get updated as expected.

From MSDN on WM_INPUT:

The application must call DefWindowProc so the system can perform cleanup.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 13
• 18
• 15
• 11
• 9