-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add a signal that is emitted when the keyboard is disconnected #6689
Comments
I'm not sure how simple this is, and I don't think you're guaranteed to get a disconnect signal from a wireless keyboard running out of battery, nor getting it fast (within several seconds, for power efficiency reasons) My assumption is that a lot of wireless keyboards don't constantly send status signals to conserve power, only sending them when updating status (keys pressed, etc.) and there's likely a poll from the receiver to check status periodically, but to conserve power (as transmitting wireless isn't very cheap power wise) it probably won't do this often, as there's usually no reason, it also prevents random disconnect events in case there's a brief loss of contact (due to interference etc.), avoiding massive annoyance in such cases The usecase would be the keyboard dying and you needing immediate update in the game, and I don't think this can be expected on a lot of hardware, though I might be wrong with modern efficiency levels etc. This would likely be very unreliable and depend on hardware so would create a lot of confusion if someone expects this to work on their hardware, I think this could only reliably work on wired keyboards, where there's no real reason to have this It should be possible to do on Linux (when the hardware supports it), but not so sure about Windows |
Keyboards do not use a gamepad-style API for (dis)connecting, so this would require listening for USB event changes which is more difficult. |
I think this is also problematic because PC could have tens of keyboards connected at the same time. But for Windows it's irrelevant as all of them are going to overlap one with another. Pressing W on keyboard 1 is equivalent to clicking W on any of them. So if we add disconnection event it's not going to mean a thing if the rest of the keyboards are still connected and are usable from system's POV. But again, how many PCs have more than 1 keyboard connected? For simple cases for PCs with just one keyboard - disconnection event is going to be a useful feature regardless!
Is this any different from listening for disconnection events for controllers that are connected by USB? Isn't this practically the same thing? On the other hand I just checked the device manager and keyboards sections looks like this Note: I only have a single keyboard connected! :) Razer thingy is the mouse.. I have no idea what it is doing in keyboard section.. If this topic/feature turns out to be too difficult to implement, just let me know and I will close this topic.. or just do it :) |
That's the problem with USB – it's a wild west: godotengine/godot#20566 This doesn't inspire me confidence in implementing this feature without negative side-effects. |
I would like to add a flaw to the idea. |
Describe the project you are working on
local coop game with monster swarming elements
Describe the problem or limitation you are having in your project
when player disconnects I would like to pause the game in order to avoid player dying in-game due to waves of monsters
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add an event to detect keyboard disconnection
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
following is the code to detect joystick disconnection in C# in godot 4.0
Similarly I would like to be able to monitor keyboard-like devices disconnection events:
alternatively it would be nice to have a single all-around method for device connection/disconnection purposes with a device type enum as parameter
the issue with last proposed solution, however, is that currently first connected controller has an device ID of 0 and so is the keyboard. If we get a disconnection event on device ID 0 then it could be either of the two, so we need an additional parameter to further understand what kind of device was disconnected. In example above I added an enum
DeviceTypeEnum
, but it might not be possible to do it like that due to sheer number of all kinds of devices available on the market, so some kind of alternative solution might be preferred.If this enhancement will not be used often, can it be worked around with a few lines of script?
can't be worked around
Is there a reason why this should be core and not an add-on in the asset library?
This should be a core feature of a Godot. Nowadays, people tend to use wireless devices, including wireless keyboards. If a keyboard gets disconnected for whatever reason (battery died or cable damage) - it can cause the player to experience some unpleasant consequences in a fast-paced game.
I think it's a very good use-case and reason for adding support for disconnect events for keyboards.
The text was updated successfully, but these errors were encountered: