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

Author Topic: Is there a way to move your mouse cursor with joystick's analog?  (Read 2892 times)

0 Members and 1 Guest are viewing this topic.

Pvt.Derpy

  • Newbie
  • *
  • Posts: 7
    • View Profile
Is there a way to move your mouse cursor with joystick's analog?
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Is there a way to move your mouse cursor with joystick's analog?
« Reply #1 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Pvt.Derpy

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Is there a way to move your mouse cursor with joystick's analog?
« Reply #2 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?

Tigre Pablito

  • Full Member
  • ***
  • Posts: 226
    • View Profile
    • Email
Re: Is there a way to move your mouse cursor with joystick's analog?
« Reply #3 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  :)

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Is there a way to move your mouse cursor with joystick's analog?
« Reply #4 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Is there a way to move your mouse cursor with joystick's analog?
« Reply #5 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?
Back to C++ gamedev with SFML in May 2023

 

anything