Latest 1.0.0
Homepage https://github.com/Clipy/Sauce
License MIT
Platforms osx 10.9
Frameworks Carbon, Cocoa
Authors

Release version
License: MIT
Carthage compatible
Version
Platform

Mapping various keyboard layout sources and key codes in macOS. (e.g.: QWERTY, Dvorak)

Requirements

  • macOS 10.9+
  • Xcode 9.0+
  • Swift 4.0+

Motivation

Only the ANSI-standard US keyboard is defined for the key code defined in Carbon.framework. Therefore, we can obtain only the key code of the QWERTY keyboard layout. (e.g.: kVK_ANSI_V)
In layout other than QWERTY, (e.g. Dvorak) the virtual key code is different.

Keyboard Layout Key Key Code
QWERTY v 9
Dvorak v 47

This library is created with the purpose of mapping the key code of the input sources and making it possible to obtain the correct key code in various keyboard layouts.

Usage

CocoaPods

pod 'Sauce'

Carthage

github "Clipy/Sauce"

Example

Key codes

Get the key code of the current input source.

let keyCode = Sauce.shared.keyCode(by: .v)

Get ASCII capable input source list.

let sources = Sauce.shared.ASCIICapableInputSources()

Get key code corresponding to input source.

let keyCode = Sauce.shared.keyCode(with: inputSource, key: .v)

Character

Get the character of the current input source.

let character = Sauce.shared.character(by: keyCode, modifiers: modifiers)

However, since character strings can only be acquired in an ASCII Capable layout, we recommend using this.

let character = Sauce.shared.currentASCIICapableCharacter(by: keyCode, modifiers: modifiers)

Notification

NSNotification.Name.SauceEnabledKeyboardInputSoucesChanged

SauceEnabledKeyboardInputSoucesChanged is the same as kTISNotifyEnabledKeyboardInputSourcesChanged in Carbon.framework

NSNotification.Name.SauceSelectedKeyboardInputSourceChanged

SauceSelectedKeyboardInputSourceChanged is different from kTISNotifySelectedKeyboardInputSourceChanged and is notified only when the input source id has changed.
Since it is filtered and notified, please do not use it for the same purpose as normal kTISNotifySelectedKeyboardInputSourceChanged.

Contributing

  1. Fork it ( https://github.com/Clipy/Sauce/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Latest podspec

{
    "name": "Sauce",
    "version": "1.0.0",
    "summary": "Mapping various keyboard layout sources and key codes in macOS. (e.g.: QWERTY, Dvorak)",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "homepage": "https://github.com/Clipy/Sauce",
    "authors": {
        "Econa77": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Clipy/Sauce.git",
        "tag": "v1.0.0"
    },
    "platforms": {
        "osx": "10.9"
    },
    "source_files": "Lib/Sauce/*.swift",
    "frameworks": [
        "Carbon",
        "Cocoa"
    ],
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This