SFML community forums

Help => General => Topic started by: Pvt.Derpy on November 11, 2018, 07:40:08 pm

Title: Is there a way to move your mouse cursor with joystick's analog?
Post by: Pvt.Derpy on November 11, 2018, 07:40:08 pm
At the moment, I am handling every event with only the mouse. Including button clicks, hover in, out etc.

I was wondering if it is possible to treat the joystick as a second mouse: if the analog moves, so does the mouse cursor. Is there a way to do so?

Another possible approach I though: create a gameobject with the resemblence of a mouse cursor and move it alongside either mouse input or joystick input. But, in this case, what happens to my events? How would I translate

if (event.mouseButton.button == sf::Mouse::Right)
?

I'm open to suggestions.

Thanks in advance.
Title: Re: Is there a way to move your mouse cursor with joystick's analog?
Post by: eXpl0it3r on November 11, 2018, 09:00:00 pm
You can set the mouse position. To be honest though that just seems like a hack, so you don't have to write more code to handle joystick events properly. ;)
Title: Re: Is there a way to move your mouse cursor with joystick's analog?
Post by: Pvt.Derpy on November 11, 2018, 09:24:06 pm
You can set the mouse position. To be honest though that just seems like a hack, so you don't have to write more code to handle joystick events properly. ;)
Mh. So, what do you suggest to achieve a sort of input independent cursor system?
Title: Re: Is there a way to move your mouse cursor with joystick's analog?
Post by: Tigre Pablito on November 12, 2018, 12:49:46 am
Hi  8)

As eXpl0it3r said, you would have to set the mouse position (according to the joystick movement)  ;)

You don't need to translate the mouse event handling, but handling the joystick event to move the mouse cursor  :P

you would need to have an X and Y vars to store the current mouse position,

then when you move the joystick to your right, then increase X, when you move up, then decrease Y, etc, etc ... (I don't know the code for this, please query C++   ::))

and then, just set mouse position to (X, Y)

sf::Mouse::setPosition(X, Y);    // I'm not sure of this cos I don't know C++, query the correct syntax  ::)

Hope this helps  :)
Title: Re: Is there a way to move your mouse cursor with joystick's analog?
Post by: Hapax on November 12, 2018, 05:56:47 pm
Moving the hardware cursor based on joystick movement doesn't seem particularly intuitive and user-friendly.
Consider using instead a software cursor (e.g. sprite) that can be controlled by both joystick and mouse if preferred.
Title: Re: Is there a way to move your mouse cursor with joystick's analog?
Post by: FRex on November 13, 2018, 03:26:08 am
It's hard to say without knowing what you're trying to achieve. Maybe a better way would be to make your game controller friendly instead in some way?