Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement keyboard localization support for player key commands#693

Merged
insidegui merged 1 commit into
insidegui:masterfrom
boettges:boettges-patch-1
Jun 8, 2023
Merged

Implement keyboard localization support for player key commands#693
insidegui merged 1 commit into
insidegui:masterfrom
boettges:boettges-patch-1

Conversation

@boettges

@boettges boettges commented Jun 7, 2023

Copy link
Copy Markdown
Contributor

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.

@allenhumphreys allenhumphreys left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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.

guard self.isEnabled else { return event }

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

Copy link
Copy Markdown
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

insidegui commented Jun 8, 2023

Copy link
Copy Markdown
Owner

Thanks @boettges!

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

@boettges

boettges commented Jun 8, 2023

Copy link
Copy Markdown
Contributor Author

@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