Hello guys. I'm capturing the keyboard input using the class below. And I have no problem doing that.
What I wanna ask is how to understand if a key is pressed, released or being pressed.
Let me explain more...
When ever any key is pressed the member function GetData() returns the virtual key code of the key which is pressed. But, if the user keeps pressing the key, the WM_INPUT message is sent periodically. The frequence of it is set at the control panel of Windows. And also, when the user releases the key, again the WM_INPUT is sent with the same virtual key code.
For example,
When user hits the escape key, 27 returns from GetData() twice. One for pressing, one for releasing.
And, when the 27 returns for the second time from GetData(), I want to find out if the key is still being pressed or the key is just released.
Waiting for your replies...
class HIDInput
{
private:
RAWINPUTDEVICE Rid;
public:
LPARAM hRawInput;
HWND hTargetWnd;
USHORT LastKey;
void Register(void)
{
Rid.usUsagePage = 0x01;
Rid.usUsage = 0x06;
Rid.dwFlags = RIDEV_INPUTSINK;
Rid.hwndTarget = hTargetWnd;
if (RegisterRawInputDevices(&Rid, 1, sizeof(Rid)) == FALSE) DebugTest("Error registering input");
}
unsigned int GetData(void)
{
UINT cbSize;
GetRawInputData((HRAWINPUT) hRawInput,
(UINT) RID_INPUT,
(LPVOID) NULL,
(PUINT) &cbSize,
(UINT) sizeof(RAWINPUTHEADER));
LPBYTE lpbBuffer = new BYTE[cbSize];
GetRawInputData((HRAWINPUT) hRawInput,
(UINT) RID_INPUT,
(LPVOID) lpbBuffer,
(PUINT) &cbSize,
(UINT) sizeof(RAWINPUTHEADER));
RAWINPUT * pRawInput = (RAWINPUT *) lpbBuffer;
if (pRawInput->header.dwType == RIM_TYPEKEYBOARD)
return LastKey = pRawInput->data.keyboard.VKey; //This one never returns 0
else
return 0; //Error
}