WM_INPUT Failing to Detect Arrow Keys
Hi guys,
I'm not getting the response I expect from WM_INPUT detecting the arrow keys:
Code:
#define key_right 0x27
USHORT key=raw->data.keyboard.VKey;
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
}
I hope you can help. Thank you.
Re: WM_INPUT Failing to Detect Arrow Keys
and raw is defined as what and is given a value from where? It would be more helpful if you posted a complete short program that demonstrated the issue.
What is the value of data.keyboard.Flags?
Re: WM_INPUT Failing to Detect Arrow Keys
Quote:
Originally Posted by
endemoniada
Hi guys,
I'm not getting the response I expect from WM_INPUT detecting the arrow keys:
Did you try to handle WM_KEYDOWN instead?
Besides, from MSDN
Quote:
Flags
Type: USHORT
Flags for scan code information. It can be one or more of the following.
Value ...............................Meaning
RI_KEY_BREAK (1)............The key is up.
RI_KEY_E0 (2)..................This is the left version of the key.
RI_KEY_E1 (4)..................This is the right version of the key.
RI_KEY_MAKE (0).............The key is down.
Re: WM_INPUT Failing to Detect Arrow Keys
Thanks for trying to help, here is a mini-program:
Code:
void OnInput(LPARAM lParam)
{
UINT dwSize;
GetRawInputData((HRAWINPUT)lParam,RID_INPUT,NULL,&dwSize,sizeof(RAWINPUTHEADER));
LPBYTE lpb=new BYTE[dwSize];
if(lpb == NULL)
return;
if(GetRawInputData((HRAWINPUT)lParam,RID_INPUT,lpb,&dwSize,sizeof(RAWINPUTHEADER)) != dwSize){
delete [] lpb;
return;
}
RAWINPUT* raw=(RAWINPUT*)lpb;
if(raw->header.dwType == RIM_TYPEKEYBOARD){
USHORT key=raw->data.keyboard.VKey;
if(key == key_right){
if(raw->data.keyboard.Flags == RI_KEY_MAKE)
face_right=1;
else if(raw->data.keyboard.Flags == RI_KEY_BREAK)
face_right=0;
}
}
}
I am getting raw->data.keyboard.Flags=2 for the arrow keys.
It's for a game and I was hoping to keep all input (keyboard, mouse, gamepad) in a centralized location, that's why I'm not using WM_KEYDOWN.
Thanks again.
Re: WM_INPUT Failing to Detect Arrow Keys
Quote:
Originally Posted by
endemoniada
I am getting raw->data.keyboard.Flags=2 for the arrow keys.
In that case you seem to get the combination (RI_KEY_MAKE | RI_KEY_E0 ) i.e.
(The key is down) | (This is the left version of the key)
Re: WM_INPUT Failing to Detect Arrow Keys
The problem is that RI_KEY_MAKE is defined to be 0 so could be taken to be this whatever the value of Flags. One way to test for up/down is
Code:
Face_right = !(raw->data.keyboard.Flags & RI_KEY_BREAK == RI_KEY_BREAK);
Re: WM_INPUT Failing to Detect Arrow Keys
It's working like a charm now. You guys are so smart, thanks a lot.
Re: WM_INPUT Failing to Detect Arrow Keys
Quote:
Originally Posted by
2kaud
The problem is that RI_KEY_MAKE is defined to be 0 so could be taken to be this whatever the value of Flags.
I don't see any problem here. Logically there can be only two possibilities for any key: either up or down.
O if it is not the up then it is down.