Raw Input... How?
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 ?
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)
When initializing:
Trap the WM_INPUT message in WndProc:
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;
}
}
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?
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement