Jump to content
  • Advertisement
Sign in to follow this  
savail

Windows raw input - problem with arrow keys

This topic is 2569 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

Hey,
I'm using windows raw input in order to handle keyboard and mouse. I heard it's recommend way of getting it... However it happens that sometimes arrow keys aren't recognised successfully, although I suppose I'm reading the keys properly:
RAWINPUT *raw;
case WM_INPUT:
UINT SizeOfBuffer;
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &SizeOfBuffer, sizeof(RAWINPUTHEADER));
BYTE Buffer[41]; //mouse size - 32, keyboard size - 40
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, Buffer, &SizeOfBuffer, sizeof(RAWINPUTHEADER));
raw = (RAWINPUT*)Buffer;
if(raw->header.dwType == RIM_TYPEKEYBOARD) //reading keyboard
{
KeyCode = raw->data.keyboard.VKey;
KeyUp[Input::Obj().KeyCode] = raw->data.keyboard.Flags & RI_KEY_BREAK;
}
if(Input::Obj().raw->header.dwType == RIM_TYPEMOUSE) //reading mouse
{
Input::Obj().MouseKeyDown = Input::Obj().raw->data.mouse.ulButtons & RI_MOUSE_LEFT_BUTTON_DOWN;
}
break;

Keycode is a virtual code of key and KeyUp is an array where I store if certain key is pushed or released and this is used by me for game needs.
Does anybody see there a problem in my code? I would be grateful for any help. Btw maybe windows raw input isn't that good?

Share this post


Link to post
Share on other sites
Advertisement
Here's how I use raw input in my game:




// Get the standard/unbuffered raw input data
if(::GetRawInputData(hRawInput, RID_INPUT, &m_oRawInput, &m_uiRawInputSize, sizeof(RAWINPUTHEADER)) != static_cast<UINT>(-1))
{
// Raw input from keyboard
if(m_oRawInput.header.dwType == RIM_TYPEKEYBOARD)
{
switch(m_oRawInput.data.keyboard.Message)
{
case WM_KEYDOWN:
switch(m_oRawInput.data.keyboard.VKey) // Virtual key
{
case VK_ESCAPE: // Escape key
onEscapeKeyDown();
break;

case VK_PAUSE: // Game_Mode_Paused key
case 'p':
case 'P':
onPauseKeyDown();
break;

case VK_PRINT: // Print key
onPrintKeyDown();
break;

case VK_LSHIFT: // Left-shift key
onLeftShiftKeyDown();
break;

case VK_RSHIFT: // Right-shift key
onRightShiftKeyDown();
break;

case VK_LCONTROL: // Left-control key
onLeftControlKeyDown();
break;

case VK_RCONTROL: // Right-control key
onRightControlKeyDown();
break;

case VK_UP: // Up key
onUpKeyDown();
break;

case VK_DOWN: // Down key
onDownKeyDown();
break;

case VK_LEFT: // Left key
onLeftKeyDown();
break;

case VK_RIGHT: // Right key
onRightKeyDown();
break;

case VK_RETURN: // Enter key
onEnterKeyDown();
break;
}
break;

case WM_KEYUP: // Key up
break;
}
}

Share this post


Link to post
Share on other sites

I'm using windows raw input in order to handle keyboard and mouse. I heard it's recommend way of getting it...
[/quote]
The recommended way of detecting keyboard and mouse input is using Windows messages.

I'm also suspicious of how you are using the buffer. The first call is to get the size of the buffer, which you do not use. Then you pass a 41 byte buffer in, but you pass SizeOfBuffer again, indicating that your buffer is SizeOfBuffer bytes long.

Share this post


Link to post
Share on other sites


I'm using windows raw input in order to handle keyboard and mouse. I heard it's recommend way of getting it...

The recommended way of detecting keyboard and mouse input is using Windows messages.[/quote]
This.

Raw input is fairly complicated, and you should only really be using it if you require high DPI mouse input (E.g. a first person shooter style game)

Share this post


Link to post
Share on other sites

I'm also suspicious of how you are using the buffer. The first call is to get the size of the buffer, which you do not use. Then you pass a 41 byte buffer in, but you pass SizeOfBuffer again, indicating that your buffer is SizeOfBuffer bytes long.

yea well firstly I'm loading required size of data to SizeOfBuffer and then I pass all these data to Buffer. Buffer has 41 size becouse I read at toymaker that 32 is needed for mouse and 40 for keyboard and so while passing the data some places in Buffer might be empty(for example if mouse is read) and that isn't that bad solution I hope.
The problem is that when I push the arrow (right for example) my character in game moves to right but when I quickly push right second time it is supposed to run right but it doesn't. If I change to another key(not arrow one) everything works fine... ;/

Share this post


Link to post
Share on other sites
Thanks a lot for everyone who posted
hmm It seems I solved the problem. I don't know why but after the arrow key is released it sends me "255" virtual code and that's why the data was wrongly placed in my array. What I've done is restrict receiving keyboard input: only if the virtual key != 255

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!