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

Implement keyboard localization support for player key commands #693

Merged
merged 1 commit into from
Jun 8, 2023

Conversation

boettges
Copy link
Contributor

@boettges boettges commented Jun 7, 2023

The changes enable consistent keyboard shortcuts for media player commands across different keyboard layouts irregardless of the localization. This is achieved by identifying commands based on the character output of keys instead of their key codes which may vary. Due to the non-textual nature of the arrow keys their input remains to be identified by their keycodes.

Example:
The current mapping for minus and plus is set to the keycodes 27 and 24.
This is not applicable to all keyboard layouts. For example, German localized ones use 44 and 30 respectively.
The proposed changes should solve this.

Thank you in advanced for reviewing and thank you for the handy app 👍

The changes enable consistent keyboard shortcuts for media player commands across different keyboard layouts irregardless of the localization. This is achieved by identifying commands based on the character output of keys instead of their key codes which may vary. Due to the non-textual nature of the arrow keys their input remains to be identified by their keycodes.
Copy link
Collaborator

@allenhumphreys allenhumphreys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is a great improvement! If you have time could you consider the adjustments I suggested?

If you don't have the time, please let us know, we could probably take this as is as both of the critical suggestions I made also apply to the existing code!

default: break
}

guard let character = event.charactersIgnoringModifiers else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading through the docs, keyCode and charactersIgnoringModifiers both say they they can raise exceptions if the event is not a key event.

addLocalMonitorForEvents(matching: .keyDown) should ensure it's always a key event, but this function could use a guard for the type of event for thoroughness.

To increase the accuracy of this function, we could also ensure no modifiers are pressed as well via event.modifierFlags.isEmpty.

@@ -1165,8 +1187,8 @@ public final class PUIPlayerView: NSView {

keyDownEventMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [unowned self] event in
guard self.isEnabled else { return event }

guard let command = KeyCommands(rawValue: event.keyCode) else {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: trailing space on empty line

@insidegui insidegui merged commit f918935 into insidegui:master Jun 8, 2023
@insidegui
Copy link
Owner

insidegui commented Jun 8, 2023

Thanks @boettges!

@allenhumphreys I'll apply your suggestions and submit another PR with just them.

@boettges
Copy link
Contributor Author

boettges commented Jun 8, 2023

@allenhumphreys Those are very valid suggestions. Thank you both!

@boettges boettges deleted the boettges-patch-1 branch June 8, 2023 19:46
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

Successfully merging this pull request may close these issues.

3 participants