Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Raw mouse input(WIN ONLY)  (Read 4129 times)

0 Members and 2 Guests are viewing this topic.

Doodlemeat

  • Guest
Raw mouse input(WIN ONLY)
« on: July 22, 2014, 06:17:12 pm »
I better throw this out to those people who is eager to use it in their games.
Unfortunately it's only implemented for windows. Reason is because I am not familiar with any other OS.

You will have to build SFML by yourself  and replace some files under in the windows module.

It is used like this:
    sf::RenderWindow window(sf::VideoMode(1920, 1080), "Title");
        window.setRelativeMouseMode(true);

Then you can capture a new event called MouseMotion
if (event.type == sf::Event::MouseMotion)
{
        event.mouseMotion.x; // Delta x
        event.mouseMotion.y; // Delta y
}

Github repository & download: https://github.com/doodlemeat/SFML-2.1-RAWINPUT

Thoughts?
« Last Edit: July 22, 2014, 06:48:07 pm by Doodlemeat »

Excellium

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Raw mouse input(WIN ONLY)
« Reply #1 on: July 22, 2014, 08:51:43 pm »
Hi ! That sounds interesting to me. Can you explain how you do this ?  :)
"Everything should be made as simple as possible, but not simpler."

Doodlemeat

  • Guest
Re: Raw mouse input(WIN ONLY)
« Reply #2 on: July 22, 2014, 10:05:17 pm »
Sure!

In the current version of SFML, they use the event WM_MOUSEMOVE which basicly returns x and y coordinates after the mouse have been moved and translated by the OS.

I am using the event WM_INPUT which returns raw data directly from the HID bypassing the OS changes. The HID can be either a mouse or a keyboard. I think there are other types of raw input devices, but I don't know any specific..

What the setRelativeMouseMode() does is that it's (en/dis)abling raw input mode. It has to be toggled on, else WM_INPUT events wont be fired at all. The raw data for the mouse contains the delta of the previous X coordinate of the mouse and the current X coordinate of the mouse. Same for Y. It also contains some information for the mouse button states, but I still doesn't know too much about it.

I hope that makes sense, because that is the best way I can explain it.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Raw mouse input(WIN ONLY)
« Reply #3 on: July 22, 2014, 10:24:42 pm »
If it helps, I think I stumbled across how to access raw input on Linux during some random googling: http://who-t.blogspot.co.uk/2009/07/xi2-recipes-part-4.html

Doodlemeat

  • Guest
Re: Raw mouse input(WIN ONLY)
« Reply #4 on: July 22, 2014, 10:31:53 pm »
You are very welcome to try to make this for Linux. I doesn't own any Linux dist and I am very sure that I will fail installing it  :o

Excellium

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Raw mouse input(WIN ONLY)
« Reply #5 on: July 23, 2014, 12:01:13 am »
There is nothing in common with hardware cursor, right ?
"Everything should be made as simple as possible, but not simpler."

Doodlemeat

  • Guest
Re: Raw mouse input(WIN ONLY)
« Reply #6 on: July 23, 2014, 12:02:40 am »
There is nothing in common with hardware cursor, right ?
Yes, you are right. Straight from the mouse ;).

Doodlemeat

  • Guest
Re: Raw mouse input(WIN ONLY)
« Reply #7 on: July 23, 2014, 12:14:15 am »
I have updated the repository to support multiple mouse devices, since I have seen some people wanting that.

Each mouse device have a unique ID. The ID comes with sf::Event::MouseMotion. The ID is received in what order the mice are plugged into the computer. Be aware of that because I had a hard time figuring this out with a game I developed that used ManyMouse script.

This is how you can identify mice.
if (event.type == sf::Event::MouseMotion)
{
        if (event.mouseMotion.index == 0) // Player 1
        {
                // Action
                event.mouseMotion.x;
                event.mouseMotion.y;
        }
        else if (event.mouseMotion.index == 1) // Player 2
        {
                // Action
                event.mouseMotion.x;
                event.mouseMotion.y;
        }
}

For example: Give each player a mouse id and you can easily check wether or not the you have received an event from that mouse.