Latest 0.1.0
Homepage https://github.com/lukaskollmer/KeyCommands
License MIT
Platforms ios 9.0
Dependencies RuntimeKit
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

KeyCommands is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "KeyCommands"

API

KeyCommands.register(_ modifiers: UIKeyModifierFlags, _ input: String, title: String? = nil, action: @escaping KeyCommand.Action) -> KeyCommand
Argument Type Discussion
modifiers UIKeyModifierFlags The bit mask of modifier keys that must be pressed. You can use this parameter to specify which modifier keys (Command, Option, and so on) must also be pressed by the user. You may specify more than one modifier key. For a list of possible values, see UIKeyModifierFlags.
input String The keys that must be pressed by the user. The string must contain one or more characters corresponding to the keys that were pressed. For a list of special characters that do not have a textual representation, see Input Strings for Special Keys.
title String? A string that can be displayed to the user to explain the purpose of the key command. Defaults to nil
action KeyCommand.Action The block to execute when the key command is pressed. The block’s only parameter is the pressed KeyCommand

KeyCommand.deregister()

Deregister a KeyCommand.

KeyCommand.register()

Re-register a KeyCommand that was deregistered via KeyCommand.register()

Examples

Basic Example

KeyCommands.register(.command, "K", title: "Clear") { _ in
    print("did press cmd+k") 
}

Register a Key Command for a View Controller’s lifetime

class ViewController: UIViewController {
    private var newFileCommand: KeyCommand!

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        newFileCommand = KeyCommands.register(.command, "N", title: "New File") { _ in
            self.createNewFile()
        }
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)

        newFileCommand.deregister()
    }
}

Author

Lukas Kollmer, [email protected]

License

KeyCommands is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "KeyCommands",
    "version": "0.1.0",
    "summary": "Nice block-based Swift API for UIKeyCommand",
    "description": "KeyCommands is an easy to use Swift wrapper around the UIKeyCommand API. It offers block support, as well as a nicer API.",
    "homepage": "https://github.com/lukaskollmer/KeyCommands",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Lukas Kollmer": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lukaskollmer/KeyCommands.git",
        "tag": "0.1.0"
    },
    "social_media_url": "https://twitter.com/lukas_kollmer",
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "KeyCommands/Classes/**/*",
    "dependencies": {
        "RuntimeKit": []
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This