Jump to content
  • Advertisement
Sign in to follow this  
Sepiantum

Raw Input... How?

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

Advertisement

So I'm working on a game, and I need to set up raw input somewhere. How would I do this?


What platform/API/Framework/Engine are you using ?

Share this post


Link to post
Share on other sites
I don't know which programming language u are using, but if you are working with C++ and with windows then I can help you.
If you are using another language, this won't help you much, but I will post it anyway.


I suggest you look here: http://www.toymaker..../raw_input.html

I also found this code in an old project (I didn't tested it again before posting it):

Global declaration (raw input for keyboard and mouse)

RAWINPUTDEVICE Rid[2];

When initializing:

// Keyboard
Rid[0].usUsagePage = 1; // generic desktop controls (default)
Rid[0].usUsage = 6; // keyboard
Rid[0].dwFlags = RIDEV_NOLEGACY; // no more messages like WM_KEYDOWN
Rid[0].hwndTarget = NULL; // don't restrict messages to a particular window

// Mouse
Rid[1].usUsagePage = 1; // generic desktop controls (default)
Rid[1].usUsage = 2; // mouse
Rid[1].dwFlags = RIDEV_NOLEGACY; // no more messages like WM_LBUTTONDOWN
Rid[1].hwndTarget = NULL; // don't restrict messages to a particular window

if (RegisterRawInputDevices(mApp->Rid, 2, sizeof(RAWINPUTDEVICE)) == FALSE)
MessageBoxW(NULL, L"Could not register the raw input device", "error", 0);

Trap the WM_INPUT message in WndProc:

case WM_INPUT:
{
UINT bufferSize = 40;
BYTE *buffer= new BYTE[40]; // mouse = 40, keyboard = 32
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, (LPVOID)buffer, &bufferSize, sizeof (RAWINPUTHEADER));

RAWINPUT *raw = (RAWINPUT*) buffer;

// Check what the input is: mouse or keyboard?
if (raw->header.dwType== RIM_TYPEMOUSE) // mouse
{
// raw->data.mouse.lLastX contains the relative X position of the mouse
// raw->data.mouse.lLastY contains the relative Y position of the mouse

// (raw->data.mouse.ulButtons & RI_MOUSE_LEFT_BUTTON_DOWN) will be 0 when left mouse button is not down.

}
else if (raw->header.dwType== RIM_TYPEKEYBOARD) //keyboard
{
// Get key value from the keyboard member (of type RAWKEYBOARD)
USHORT keyCode = raw->data.keyboard.VKey;
}
}

Share this post


Link to post
Share on other sites
I read a few more posts about Raw Input and I found out that all you get is last action that happened. How do you transform this data into useful key_up/key_down/key_held information?

Share this post


Link to post
Share on other sites
Please answer Simon's question. I think you may not be getting the best information.

Share this post


Link to post
Share on other sites
I encountered another problem. When using raw input for mouse input, my cursor stays busy. I know it's not my handling code because I commented out all of it and it still gives me a busy cursor. Not registering the mouse for raw input fixes the problem but I don't get to use raw input for mice. Any help?

Share this post


Link to post
Share on other sites
It seems to me as if I have pinpointed the problem. Keeping the mouse at RIDEV_NOLEGACY will cause a constant busy cursor and will hang your process at some points. Setting that to 0 will fix the problem. But why is this?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!