Swiftpack.co - Clipy/Sauce as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Clipy.
Clipy/Sauce v2.4.1
Mapping various keyboard layout sources and key codes in macOS. (e.g.: QWERTY, Dvorak)
⭐️ 64
🕓 2 weeks ago
macOS
.package(url: "https://github.com/Clipy/Sauce.git", from: "v2.4.1")

Sauce

CI Release version License: MIT Carthage compatible Version Platform SPM supported

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

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(for: .v)

Key

Get the Key of the current input source.

let key = Sauce.shared.key(for: keyCode)

Character

Get the character of the current input source.

let character = Sauce.shared.character(for: keyCode, carbonModifiers: shiftKey)
let character = Sauce.shared.character(for: keyCode, cocoaModifiers: [.shift])

Notification

NSNotification.Name.SauceEnabledKeyboardInputSourcesChanged

SauceEnabledKeyboardInputSourcesChanged 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.

NSNotification.Name.SauceSelectedKeyboardKeyCodesChanged

By using this Notification, can detect when the setting changes with the same keyboard layout, when the input source changes from QWERTY to Dvorak, and so on.

GitHub

link
Stars: 64
Last commit: 2 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v2.4.1
2 weeks ago

Enhancements

  • Make access open for mocking/subclassing ( #56 ) @jasonm23
  • Conform Key to Sendable ( #63 ) @zshannon
  • Add #if os(macOS) macro ( #64 ) @akring

Bugfixes

  • None.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics