-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Update InputEventKey doc: Clarify behavior when setting event properties #84836
base: master
Are you sure you want to change the base?
Conversation
I don't think this explains the problem. You're just describing the nature of all properties to be set to their default value on creation, which is true for any Variant, not just The core of #84731 is assuming setting one of |
Or it's just the name confuses them, a little hard to clarify though. |
Not really, the confusion is that people assume they are linked and update together, and aren't separate properties |
I think adding docs here is useful, as the behavior is far from obvious. It's not an oversight that only one of But to fix #84731 itself, I would add documentation to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Event mappings should have only one of the [member keycode], [member physical_keycode], or [member unicode] set.
Seems a bit excessive, this part already describes the same behavior.
Another possible cause is that the 4.1.3 documentation for godot/doc/classes/InputEventKey.xml Lines 80 to 83 in 2d3b2ab
|
7939011
to
b2c88af
Compare
My point is that And the event is one they receive and they don't know ahead of time if it's physical or not, they basically need to reimplement the internal logic we use: OS.get_keycode_string(event.physical_keycode if event.keycode == KEY_NONE else event.keycode) which doesn't feel very satisfactory as API design, but at least this can be documented. |
I do feel a little curious about this, why we have to store all three fields together instead of a tagged union or something like a variant to represent a InputKeyEvent, is there any corner cases that we need consider? |
Because we don't usually do that and it's not necessary simple or stable to do so I'd say |
They should know what they want to get. Physical keycode and keycode are in different domains. A physical "E" and a regular "E" are two different keys. #84731 can only be handled reasonably in 4.2 via the new API: OS.get_keycode_string(DisplayServer.keyboard_get_keycode_from_physical(e.physical_keycode)) And this is already documented in i.e. The issue is not a miss use of |
Right, see also #82092. |
b2c88af
to
0ae61d8
Compare
If we don't need to store keycode and phyiscal keycode simultaneously, I believe this adds more weight to my initial thought of use a tagged union to store all these fields, in this way we can print some warning when user try to access the incorrect field. But I suspect it will break compatibility, the public interface doesn't have to change, but the serialized format will change. |
It would require a lot of potentially fragile code to access and update the data, I'd say it's not worth it for a little data savings (you'd save at most one 32 bit value, as the flag for which type is stored would be aligned, so you'd at most save one 32 bit value) |
Not for data saving, but for prevent get the wrong data. Maybe add a tag will do the same, but as you said, it is more work compared to gain. Should be designed from day 1. |
Fixes #84731
Suggestions are welcomed as I'm not a native English speaker.