Jump to content
  • Advertisement
Sign in to follow this  
Endemoniada

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Edited by Vortez

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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.

Edited by Endemoniada

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!