-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect when a controller is connected/disconnected? #76
Comments
I think this project is dead. But I'm playing around with the console demo right now. I think you can create a new InputManger in the background (own thread) every x seconds and check if the list of joysticks matches the list of the old manger. If not, a new joystick has been added or removed. |
I would say - doing this in a thread/spinning up various instances of the manager would not be ideal. When I created OIS way back (haven't done any work on it in many years myself), I envisioned disconnect/reconnect support in the lib (e.g. for console's, less common for PC back then) - It should be possible to add a new event type, and periodically scan for new devices, and detect reconnects inside the manager itself. Some bit of OS specific logic needed perhaps in some parts. I may look into this one day - if you have time now, would be a great addition. |
I would also destroy the instance again if nothing has changed and if something has changed overwrite the old one with the new one. Is also not very clean. I looked at the code and there are many places where lists and variables are filled when the manager is initialized. It's not just a new event. Implementing that is a lot of work. Probably that's why the function doesn't exist. |
The main issue, and why it was never fully realized, is none of the APIs are great (directinput, xinput) for handling this. They are not geared towards this so much. I may tackle it though, definitely wanting to get back into C++ a bit more, been doing C# almost exclusively for years now. I may take a stab at the Linux side - they are just standard HID devices in udev. |
The detection of connected/disconnected works under Windows with SDL2 without problems. But unfortunately I have other problems with SDL2 and can't use it on Linux and OSX for some reasons. I put this workaround on a keyboard key in the console demo and it worked just fine. But I only tested this workaround on Windows. But doing that every second actually sounds horrible. I'd have to take a look at how SDL2 does it. |
Is there a way to detect when a controller is connected/disconnected? If not, are there any ideas on how I could implement a connected/disconnected event?
The text was updated successfully, but these errors were encountered: