cocoabits / MASShortcut

Modern framework for managing global keyboard shortcuts compatible with Mac App Store. More details:
http://blog.shpakovski.com/2012/07/global-keyboard-shortcuts-in-cocoa.html
BSD 2-Clause "Simplified" License
1.52k stars 220 forks source link

Support for generating correct keyEquivalents for function keys. #169

Closed GetToSet closed 3 years ago

GetToSet commented 3 years ago

My use case involves setting keyCodeStringForKeyEquivalents of MASShortcuts directly into NSButtons' keyEquivalent properties.

Screenshot 2021-10-11 AM 12 29 14

MASShortcut class can help simplify display logic for special function keys such as "←". However, I found that keyCodeStringForKeyEquivalents of functions keys such as arrow, backspace, return and alike returns empty.

This PR:

  1. Removes keyCodeString.length <= 1 testing in -[MASShortcut keyCodeStringForKeyEquivalent] since only keyCodeStrings of F keys contains multiple charactes.
  2. Makes keyCodeStringForKeyEquivalent aligned up with keyCodeString. All keys are tested and should work, except for space and tab.
    • Using space for keyEquivalent is not supported by AppKit, see here.
    • Currently, tabs cannot be recorded by MASShortcutView.
  3. Adds kMASShortcutFuctionKey definitions for missing NS*FunctionKeys outside of Unicode private range. Although definitions some keys (like NSBackspaceCharacter) can be found elsewhere in AppKit headers, this helps to make code consistent.
  4. Replaces hared-coded values (119 and 115) into (kVK_Home and kVK_End) and adds comment for kVK_Help, which actually represents for 'Insert' on most keyboards.