-
April 16th, 2014, 11:08 AM
#1
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.
-
April 16th, 2014, 11:14 AM
#2
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?
Last edited by 2kaud; April 16th, 2014 at 01:02 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 16th, 2014, 11:38 AM
#3
Re: WM_INPUT Failing to Detect Arrow Keys
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
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.
Victor Nijegorodov
-
April 16th, 2014, 02:58 PM
#4
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.
-
April 16th, 2014, 03:32 PM
#5
Re: WM_INPUT Failing to Detect Arrow Keys
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)
Victor Nijegorodov
-
April 16th, 2014, 04:17 PM
#6
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);
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 16th, 2014, 07:34 PM
#7
Re: WM_INPUT Failing to Detect Arrow Keys
It's working like a charm now. You guys are so smart, thanks a lot.
-
April 17th, 2014, 01:03 AM
#8
Re: WM_INPUT Failing to Detect Arrow Keys
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.
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|