The easiest way to add comprehensive hardware keyboard control to an iPad, iPhone, or Mac Catalyst app.
Keyboard control is a standard expectation of Mac apps. It’s important on iOS too because a hardware keyboard improves speed and ergonomics, which makes an iPad an even more powerful productivity machine.
KeyboardKit is designed to integrate with the UIKit focus system when available (iPad with iOS 15+, macOS 11+), and it provides similar arrow and tab key navigation on OS versions where the focus system is not available (iPhone, iPad with iOS 13–14, macOS 10.15).
- Keyboard navigation without the focus system (navigate with arrow keys and tab key)
- Additional navigation commands (dismiss modals, change tabs, go back)
- Collection view and table view commands (reorder, delete, select all)
- Keyboard scrolling and zooming (including page up, page down, home, end — and map views)
- Key equivalents for buttons (SwiftUI buttons, UIKit bar button items)
- Advanced text navigation (find next/previous, define)
- Keyboard window management (open, close, cycle)
- Keyboard date picker (change day, week, month or year)
- Main menu and discoverability HUD (group commands under File, Edit, View etc.)
- Discoverability titles in 39 localisations
Xcode 14.1 or later is required. KeyboardKit supports iOS 13 onwards on iPad and iPhone and macOS 11 onwards with Mac Catalyst (both scaled and optimised). tvOS is not supported. The framework builds for visionOS, but this platform has not been tested.
Add KeyboardKit to an existing Xcode project as a package dependency:
- Navigate to your project settings and then the Package Dependencies tab.
- Click the + button.
- Enter https://github.com/douglashill/KeyboardKit into the search or package URL field.
- Clone this repository.
- Drag
KeyboardKit.xcodeproj
into your Xcode project. - Add the KeyboardKit target as a dependency of your target.
- Add
KeyboardKit.framework
to your target as an embedded framework.
Swift Package Manager requires the Swift and Objective-C sources to be separated into modules. The KeyboardKitObjC
module is used internally by KeyboardKit and does not need to be imported explicitly by your app.
Up until version 8.2.0, KeyboardKit was available on CocoaPods as Keyboard-Kit
. Please use Swift Package Manager or direct installation instead.
Import the framework:
import KeyboardKit
Instead of creating or subclassing a UIKit class directly, use the subclasses from KeyboardKit instead. All KeyboardKit subclasses are named by changing UI
to Keyboard
. For example replace
class SettingsViewController: UICollectionViewController {
...
}
with
class SettingsViewController: KeyboardCollectionViewController {
...
}
Or create KeyboardKit subclasses directly:
let tabBarController = KeyboardTabBarController()
tabBarController.viewControllers = [
KeyboardNavigationController(rootViewController: SettingsViewController()),
]
In order to receive key commands, an object must be on the responder chain.
You can see more in the KeyboardKitDemo app, and each class includes API documentation in their Swift source file.
When using the .keyboardShortcut
modifier on a Button
, access semantically defined KeyboardShortcut
s for common actions within the .KeyboardKit
namespace:
Button("Save") {
// Save something here in the button action
}
.keyboardShortcut(.KeyboardKit.save)
This adds the ability trigger the action of the button by pressing ⌘S.
- The creation of KeyboardKit
- Conference talk: Keyboard control in UIKit apps at iOS Conf SG 2020
- Podcast discussion: iPhreaks episode 297
- What’s new in KeyboardKit for iOS 14?
- Migrating KeyboardKit to Swift 6 language mode.
- Change log
KeyboardKit is a project from Douglas Hill with the generous help of contributors. Some concepts were originally developed for PSPDFKit and reimplemented in Swift for KeyboardKit. I use KeyboardKit in my reading app.
I’d love to have help on this project. For small changes please open a pull request; for larger changes please open an issue first to discuss what you’d like to see.
Tests are not required for new functionality, but fixed regressions should have automated tests. Use KeyboardKitTests
for unit tests that don’t need views or a responder chain. Use KeyboardKitDemoUITests
for integration tests that can be reproduced in the demo app. This only works on Mac Catalyst currently because iOS does not allow simulating hardware keyboard input. Use KeyboardKitUITests
for any test cases between, which is probably most cases.
MIT license — see License.txt