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

Author Topic: Mouse capture/grab  (Read 56708 times)

0 Members and 1 Guest are viewing this topic.

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Mouse capture/grab
« on: November 26, 2009, 07:37:10 pm »
I thought this would have been discussed before, but didn't find anything. A proper mouse capture/input grab mode would be very helpful. Resetting the cursor to the window center is not only a hack, but also fails if the mouse moves too quickly.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Mouse capture/grab
« Reply #1 on: November 26, 2009, 07:43:11 pm »
Reseting mouse position on MouseMove event doesn't work for this?

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Mouse capture/grab
« Reply #2 on: November 26, 2009, 07:44:16 pm »
Quote from: "panithadrum"
Reseting mouse position on MouseMove event doesn't work for this?


Quote from: "l0calh05t"
Resetting the cursor to the window center is not only a hack, but also fails if the mouse moves too quickly.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Mouse capture/grab
« Reply #3 on: November 26, 2009, 07:48:09 pm »
What happens in grab mode when the cursor reaches the border of the window?
Laurent Gomila - SFML developer

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Mouse capture/grab
« Reply #4 on: November 26, 2009, 08:08:23 pm »
In most programs which implement cursor grabbing, the cursor is locked to the client area.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Mouse capture/grab
« Reply #5 on: November 26, 2009, 08:36:28 pm »
So how can you continue to move whatever is linked to the mouse, when the cursor is stuck on the border?
Laurent Gomila - SFML developer

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Mouse capture/grab
« Reply #6 on: November 27, 2009, 08:35:57 am »
ah, sorry I think there is a small misunderstanding here, input capture in win32 means catching all input, even that for other windows, in that case the mouse would just continue and we would get mouse messages with values outside the client area (therefore with x/y negative or or large position values). this can be useful for things like drag&drop etc. useful but not what i meant ;-)

i'm rather thinking about the behavior in many games where you cannot move the mouse outside the window, for example in an fps. or whenever else we don't use the mouse to point at anything. (vm's often do this as well)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Mouse capture/grab
« Reply #7 on: November 27, 2009, 08:41:32 am »
Quote
i'm rather thinking about the behavior in many games where you cannot move the mouse outside the window, for example in an fps. or whenever else we don't use the mouse to point at anything. (vm's often do this as well)

My question still applies: what happens when the mouse reaches the border of the window? In a FPS you would be stuck rotating the player, isn't it?
Laurent Gomila - SFML developer

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Mouse capture/grab
« Reply #8 on: November 27, 2009, 08:55:24 am »
Ah, no, the way I meant it (and GLFW does it when the mouse is hidden/locked) the actual hardware cursor does not move at all so we are basically working on mouse position deltas.

As far as I can tell from a cursory glance at the GLFW sources, it also only resets the cursor to the window center, but it does it internally and apparently that is enough to stop the cursor from leaving the window.

EDIT: But locking the cursor to the client area would also work for me, in that case we can just do the reset to center ourselves, which would merely result in a clamping of the rotation speed in the fps example.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Mouse capture/grab
« Reply #9 on: November 27, 2009, 09:01:03 am »
So we're back to the good old "hack", finally.

I'll take a look at GLFW and see how they manage to keep the cursor inside the window. Maybe they use mouse capture (like in Win32) so that the mouse move events are still received if the cursors leaves the window due to a quick move.
Laurent Gomila - SFML developer

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Mouse capture/grab
« Reply #10 on: November 27, 2009, 09:12:39 am »
Quote from: "Laurent"
So we're back to the good old "hack", finally.

I'll take a look at GLFW and see how they manage to keep the cursor inside the window. Maybe they use mouse capture (like in Win32) so that the mouse move events are still received if the cursors leaves the window due to a quick move.


It's a hack if we (as a user) do it externally, because this is not fast enough and doesn't work.

I also added this

Code: [Select]
case sf::Event::MouseLeft:
if(cursorLocked)
window->SetCursorPosition(window->GetWidth()/2,window->GetHeight()/2);
break;

to my code, but the mouse cursor is still visible outside the window for a moment, but at least it isn't lost

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Mouse capture/grab
« Reply #11 on: November 27, 2009, 09:18:14 am »
I understand. Like I said, I'll see if I can come up with a clean and efficient solution.
Laurent Gomila - SFML developer

l0calh05t

  • Full Member
  • ***
  • Posts: 200
    • View Profile
Mouse capture/grab
« Reply #12 on: July 08, 2010, 12:09:04 am »

Krosan

  • Newbie
  • *
  • Posts: 10
    • View Profile
Mouse capture/grab
« Reply #13 on: July 08, 2010, 08:20:44 am »
The input system OIS is able do do that on windows and linux, maybe you can get there informations

here the sourceforge:
http://sourceforge.net/projects/wgois/

Tronic

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • http://performous.org/
Mouse capture/grab
« Reply #14 on: August 13, 2010, 03:04:01 am »
It would be optimal if raw mouse movements could be read, avoiding the concept of screen pixels, desktop acceleration/speed adjustment and other cruft entirely, but unfortunately I don't think this is very practical on Windows nor Linux. On Linux you could read the input event device directly, but that requires root access :(

Even so, it would be very good if SFML offered an API for this kind of mouse control and then internally implemented the best known solution for each platform. The current way of application programmers having to hack something together is the worst solution.

In such an API, the user wants to know how much the mouse has moved since the last read, without having to wonder about window center coordinates or other such things. This should also always hide the cursor.

 

anything