-
Notifications
You must be signed in to change notification settings - Fork 627
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
Change: Make Command a valid modifier on OS-X #759
Conversation
Hmm, just thought of a (mild) flaw in this :/ Now, the obvious answer to that is just to add it to the enum, but I don't particularly like adding something at the start of the enum (Within the existing modifiers section) when it'll be a nightmare to check that our codebase isn't using the int representation for a key somewhere, let alone what third parties may or may not be doing...... Need some input from the maintainers here: |
The second commit adds the Command key to the enum, and actually makes this work. Still need some maintainer input as to whether this is the best route mind :) Testing status:
Still concerned about any edge cases though. Whilst I can't think of any off the top of my head, the Key enum is used everywhere in the keyboard handling, and is a perfect candidate for biting us. |
Thank you for you contribution! Currently, the In order to avoid clutter in our pull requests, we're going to be closing any pull request that isn't targeting 4.0 on the 31st of July, 2018. Please rebase your pull request before then. |
Rebased & squelched into a single commit. |
|
||
if (command) | ||
{ | ||
OnKeyDown(Key.Command, KeyboardState[Key.AltLeft]); |
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.
Is the use of the alt left key here intentional?
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.
It's intentional, copying the pattern from those above.
Modifiers on OS-X / Cocoa don't generate a keydown state event per-se, but rather are passed as flags in a window event message (Including ALT).
If I understand the intent of the original code correctly, the virtual LeftAlt key is being used to define that any given modifier was valid at the last keypress event, and the modifiers flags are used to determine which.
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.
That.... doesn't seem to make much sense to me. Why would a modifier not be valid? Also this method seems only called by the cocoanative window and I still cant get CMD+V to work. This seems like a typo to me tbh, and the reason why CMD+V doesnt work. Testing now...
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.
Because a modifier isn't a key & generates no events.
We can therefore hold one key and a modifier. Release the modifier while holding the key & press another.
The first is now invalid, but no keypress events have been generated.
If this don't make sense it's because its from the phone....
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.
Oh, but I just realize that this second argument just sets the KeyDownArgs.IsRepeat field to determine if its a key repeat event when holding down the key for a longer time.
The first is now invalid, but no keypress events have been generated.
Keypress events do not consider the modifiers anyway though (at least not OpenTK, the Operating system does). Only the keydown events pass on the modifiers. And opentk registers any cocoa keydown/keyup events so even your case should be handled correctly.
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.
It's marginally crappy code, but rehacking the keypress events for the native window isn't something I'm going after on my own.
|
||
if (command) | ||
{ | ||
OnKeyDown(Key.Command, KeyboardState[Key.AltLeft]); |
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.
It's intentional, copying the pattern from those above.
Modifiers on OS-X / Cocoa don't generate a keydown state event per-se, but rather are passed as flags in a window event message (Including ALT).
If I understand the intent of the original code correctly, the virtual LeftAlt key is being used to define that any given modifier was valid at the last keypress event, and the modifiers flags are used to determine which.
Alright, seems fine. I'll merge it, and we can test it as a part of the general 4.0 overview. |
@@ -121,6 +121,10 @@ public enum Key | |||
/// </summary> | |||
Menu, | |||
|
|||
/// <summary>The Command key.</summary> | |||
/// <remarks>Valid on OS-X only</remarks> | |||
Command, |
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.
Argggh, this took me like 4 hours to figure out.
I tried your patch on my fork. This one enum entry broke all keyboard inputs on mac os for my game because it caused all subsequent enum indices to be shifted by 1 which caused my game internal keycode representation to be incorrectly mapped.
This is not a bug per se but perhaps its a good idea to move this enum entry to the very bottom for backwards compatibility?
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.
Dunno.
I would have thought most people are using the actual enum values, rather than the index directly?
It was deliberately added there so it was grouped with the other OS-X modifiers rather than elsewhere.
You've absolutely proved my point about this biting us though!
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.
I have an abstraction layer to abstract away OpenTK itself so I can switch to another graphics library / toolkit should the need ever arise, hence the mapping
Hokay, more tests revealed that the keydown event for the command key itself is fired and works. But when you do a key combination like Command + V the KeyboardKeyEventArgs for that keydown event does not have the Command modifier flag set to on because you forgot to patch KeyboardKeyEventArgs.cs |
Found even more bugs. Using Command+V also triggers a Keypress event for 'V', which it shouldn't. Judging by the lack of information on that in the online apple cocoa documentation we have to literally hardcode those special cases. The windows implementation handles this by listening to a CHAR event so neatly does the work for us when handling hotkeys (as in, not trigger a keypress when such shortkey is used). |
@tyronx Should report those bugs in a new issue ;) |
Purpose of this PR
Testing status
Untested- I've got no physical hardware, but assuming the NSEventModifierMask for Command is correct it's a simple change.See below.Comments
#757