How to create Ipad keyboard shortcut list

Hi, my app has a few in-app shortcuts which are controlled in the app. When I am on my Ipad with a hardware keyboard and using some other apps (like apple’s “notes”), I can press and hold the “Command” key for a few seconds and a list of these shortcuts appear (see below). I would like to list mine in the app like this but haven’t seen what it is called or how to do this.

Accepted Reply

I found the solution: I found this page on adding hardware keyboard support to your app which had the answer: https://developer.apple.com/videos/play/wwdc2020/10109/

To achieve this you simply override the UIKeyCommand property in the view controller class you want the shortcut to be available in and set the properties accordingly, example below. You may also need to ensure your vc is the first responder.

override var keyCommands: [UIKeyCommand]? {
		if #available(iOS 13.0, *) {
			return [
				UIKeyCommand(title: "test action", action: #selector(keyPressureTest), input: "m", modifierFlags: .command),
				UIKeyCommand(title: "test action 2", action: #selector(keyPressureTest), input: "m")
			]
		} else {
			// Fallback on earlier versions
			return []
		}
	}

	@objc func keyPressureTest() {
		print("shortcut action completed")
	}

Replies

I found the solution: I found this page on adding hardware keyboard support to your app which had the answer: https://developer.apple.com/videos/play/wwdc2020/10109/

To achieve this you simply override the UIKeyCommand property in the view controller class you want the shortcut to be available in and set the properties accordingly, example below. You may also need to ensure your vc is the first responder.

override var keyCommands: [UIKeyCommand]? {
		if #available(iOS 13.0, *) {
			return [
				UIKeyCommand(title: "test action", action: #selector(keyPressureTest), input: "m", modifierFlags: .command),
				UIKeyCommand(title: "test action 2", action: #selector(keyPressureTest), input: "m")
			]
		} else {
			// Fallback on earlier versions
			return []
		}
	}

	@objc func keyPressureTest() {
		print("shortcut action completed")
	}