WM_INPUT with Arrow Keys Failing

Started by
3 comments, last by Endurion 10 years ago

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;
}

Advertisement

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 smile.png ), 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.

I never used rawinput, so i can't help you much. Just saying (i know, im an optimization freak smile.png ), 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.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


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.

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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement