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

Author Topic: Add Keyboard/Mouse connection detection  (Read 4843 times)

0 Members and 1 Guest are viewing this topic.

DeathRay2K

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Add Keyboard/Mouse connection detection
« on: December 09, 2016, 07:26:21 pm »
It would be useful to be able to check if a keyboard or mouse is or is not connected to the computer.

My use case is this:
I have a Windows program with UI, when a user is using a mouse, I want them to activate hover events, and when they are using a touch screen, I don't want to activate hover events.
The way Windows emulates mouse inputs with a touchscreen makes this impossible in SFML, as the MouseMove event is triggered so it appears the mouse is hovering over a button after the tap completes.

Another use case:
I have a mobile app with text input fields. I want to bring up the virtual keyboard when the user taps on an input field, unless they have a physical keyboard connected to their device.
I believe this is currently impossible in SFML, but I don't develop for Android/iOS so correct me if I'm wrong.

I think it makes the most sense to be able to poll the connection status in sf::Mouse and sf::Keyboard.
Alternatively a rework of the Mouse and Keyboard classes to bring them closer to how Joysticks are implemented might make sense, as it would allow multiple keyboards and mice to be detected as well. I realise that would at least have to wait for SFML3, and may not be a common enough scenario to warrant the effort.

IngloriousTom

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Add Keyboard/Mouse connection detection
« Reply #1 on: December 12, 2016, 01:48:33 pm »
For your first use case, I believe you should wait for sf::Event::TouchEvent to be implemented on PC. This way you could differentiate between a mousemove and a touchmove. If you can't wait, there is a pull request, you just need to apply it and build SFML yourself.

DeathRay2K

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Email
Re: Add Keyboard/Mouse connection detection
« Reply #2 on: January 16, 2017, 09:02:23 pm »
I do use that pull request, but it doesn't address the issue completely. In fact I don't see a good way to distinguish between a mousemove and a touchmove even with that pull request, as both get sent when you touch the screen.

I just checked and it does look like it's been updated since I last compiled with that PR, so maybe it actually does work properly now.  ??? But in any case it doesn't enable the other use case

IngloriousTom

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Add Keyboard/Mouse connection detection
« Reply #3 on: January 23, 2017, 02:09:21 pm »
Effectively it looks like on Windows a touch move will generate a mouse move too, but you can distinguish this mouse move from others mouse move: see https://msdn.microsoft.com/en-us/library/dd693088(v=VS.85).aspx

I don't know if mario's pull request manage it, but since it's tagged for the next release, it certainly should be implemented.

 

anything