Raw Input... How?

Started by
13 comments, last by shurcool 12 years, 10 months ago
So I'm working on a game, and I need to set up raw input somewhere. How would I do this?
Follow and support my game engine (still in very basic development)? Link
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 ?
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
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;
}
}
TGUI, a C++ GUI for SFML
texus.me
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?
Follow and support my game engine (still in very basic development)? Link
Please answer Simon's question. I think you may not be getting the best information.
I'm using DirectX and writing my own engine.
Follow and support my game engine (still in very basic development)? Link
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?
Follow and support my game engine (still in very basic development)? Link
Why are you using raw input?
So I don't have to worry about any other windows messages for input other than WM_INPUT
Follow and support my game engine (still in very basic development)? Link
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?
Follow and support my game engine (still in very basic development)? Link

This topic is closed to new replies.

Advertisement