Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clipy/sauce
Mapping various keyboard layout sources and key codes in macOS. (e.g.: QWERTY, Dvorak)
https://github.com/clipy/sauce
dvorak keycode macos qwerty swift
Last synced: 7 days ago
JSON representation
Mapping various keyboard layout sources and key codes in macOS. (e.g.: QWERTY, Dvorak)
- Host: GitHub
- URL: https://github.com/clipy/sauce
- Owner: Clipy
- License: mit
- Created: 2018-07-28T18:46:25.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-06T00:41:48.000Z (about 2 months ago)
- Last Synced: 2024-12-07T14:21:00.106Z (15 days ago)
- Topics: dvorak, keycode, macos, qwerty, swift
- Language: Swift
- Homepage:
- Size: 137 KB
- Stars: 74
- Watchers: 5
- Forks: 19
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Sauce
![CI](https://github.com/Clipy/Sauce/workflows/Xcode-Build/badge.svg)
[![Release version](https://img.shields.io/github/release/Clipy/Sauce.svg)](https://github.com/Clipy/Sauce/releases/latest)
[![License: MIT](https://img.shields.io/github/license/Clipy/Sauce.svg)](https://github.com/Clipy/Sauce/blob/master/LICENSE)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Version](https://img.shields.io/cocoapods/v/Sauce.svg)](https://cocoapods.org/pods/Sauce)
[![Platform](https://img.shields.io/cocoapods/p/Sauce.svg)](https://cocoapods.org/pods/Sauce)
[![SPM supported](https://img.shields.io/badge/SPM-supported-DE5C43.svg?style=flat)](https://swift.org/package-manager)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.```swift
let keyCode = Sauce.shared.keyCode(for: .v)
```### Key
Get the `Key` of the current input source.```swift
let key = Sauce.shared.key(for: keyCode)
```### Character
Get the character of the current input source.```swift
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.