Skip to content
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

Open
BioAbnerUAD opened this issue Nov 25, 2021 · 5 comments
Open

Detect when a controller is connected/disconnected? #76

BioAbnerUAD opened this issue Nov 25, 2021 · 5 comments

Comments

@BioAbnerUAD
Copy link

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?

@Socke81
Copy link

Socke81 commented Mar 4, 2022

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.

@pjcast
Copy link

pjcast commented Mar 4, 2022

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.

@Socke81
Copy link

Socke81 commented Mar 4, 2022

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.

@pjcast
Copy link

pjcast commented Mar 4, 2022

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.

@Socke81
Copy link

Socke81 commented Mar 4, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants