antongaenko/keybro
Keybro - is a quick wrapper for UIKeyCommand. This tool allows easily adding keyboard shortcuts to your app for debugging and testing applications especially in a simulator.
What is it?
It's a wrapper for UIKeyCommand which allows you to easily create keyboard shortcuts for your iOS app. It can speed up development and manual testing apps in simulator. This micro lib contains one file and only 120 lines of code. You can run an example app, run pod try Keybro or scroll below for inspiration.
Why?
If you check how many times you repeat the same actions during development (drag cursor, click, scroll, drag again, click and so on), you may recognize that doing the same with keyboard shortcuts can save you some time and effort. Actually you can just use UIKeyCommand if you don't want to use this micro lib and get the same results. It's up to you.
Examples
The main purpose of this project is to give your ideas and basic tools.
A) Show specific screens and close them without single touch (link to source code)
<img src=https://raw.githubusercontent.com/antongaenko/d/main/keybro/scenario.gif width=200>
B) Loop through controls on a screen (link to source code)
<img src=https://raw.githubusercontent.com/antongaenko/d/main/keybro/controls.gif width=200>
C) Use space for scrolling content (link to source code)
<img src=https://raw.githubusercontent.com/antongaenko/d/main/keybro/space.gif width=200>
D) Use numeric pad to enter pass code (link to source code)
<img src=https://raw.githubusercontent.com/antongaenko/d/main/keybro/digits.gif width=200>
E) Use arrows β β for app navigation (link to source code)
<img src=https://raw.githubusercontent.com/antongaenko/d/main/keybro/arrows.gif width=200>
F) Switch tabs in tab controller (link to source code)
<img src=https://raw.githubusercontent.com/antongaenko/d/main/keybro/tabs.gif width=200>
G) Return a keyboard shortcut to toggle on/off Slow animations mode or show debug menu (link to source code)
<img src=https://raw.githubusercontent.com/antongaenko/d/main/keybro/animation.gif width=200>
H) Or make some useless and fun things like zooming π« (link to source code)
<img src=https://raw.githubusercontent.com/antongaenko/d/main/keybro/zoom.gif width=200>
Installation
Swift Package Manager
Package name is Keybro and full package link is https://github.com/antongaenko/keybro.
Cocoapods
### Manual
Just download and add `Keybro.swift` as a source file to your project (its 120 lines of code).
How to use?
Call methods on UIViewController instance: add(command: Command) or add(commands: [Command]).
If you want to add keyboard shortcuts only in debug builds just use addDebug(command: Command) or addDebug(commands: [Command]) methods.
You can call removeAllCommands() at any time to remove commands attached to the current view controller. There is no need to call it in simple cases.
For example for predefined keys (space, enter, backspace, digits, tab) you can write:
controller.add(commands: [.space(dismiss), .enter(dismiss), .backspace(dismiss)])Check this full example ScenariosExampleViewController
For custom keys with arrows you can write:
navigationController.add(commands: [
.custom(input: UIKeyCommand.inputRightArrow, modifiers: [], action: { [weak navigationController] in
navigationController?.pushViewController(LoopThroughExampleViewController(), animated: true)
}),
.custom(input: UIKeyCommand.inputLeftArrow, modifiers: [], action: { [weak navigationController] in
navigationController?.popViewController(animated: true)
})
])Check full example AppDelegate
Don't forget using weak reference in action blocks of commands.
Some keyboard shortcuts will not work because conflicts with system ones. You can change a modifier in such case.
Contributing
If you find any bug please open an issue and provide details.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Afterwords
If you find this project useful for you and your team, spread the word and star this project. Good luck and happy coding! πββοΈ
Package Metadata
Repository: antongaenko/keybro
Homepage: https://github.com/antongaenko/keybro
Stars: 16
Forks: 1
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
Topics: debug, developer-tools, ios, keyboard, shortcuts, simulator, swift, testing, tool, uikeycommand
README: README.md