uikeycommand

SwiftUI iOS - how to capture hardware key events

妖精的绣舞 提交于 2020-06-14 08:28:10
问题 I’m new to iOS development. Following a tutorial I have created a simple calculator using SwiftUI. I have a keyboard attached to my iPad, and I would like to be able to enter values using the keyboard. How can I capture and handle hardware keyboard events in a SwiftUI app (with no text field) ? I have tried to use the keyCommands on the SceneDelegate (UIResponder) as shown here, but that doesn’t work for me. As soon as I press any key on my iPad, I get “Connection to deamon was invalidated”

Stop UIKeyCommand repeated actions

我怕爱的太早我们不能终老 提交于 2020-06-12 04:11:20
问题 If a key command is registered, it's action might be called many times if the user holds down the key too long. This can create very weird effects, like ⌘N could repeatedly open a new view many times. Is there any easy way to stop this behavior without resorting to something like a boolean "already triggered" flag? Here's how I register two different key commands: #pragma mark - KeyCommands - (BOOL)canBecomeFirstResponder { return YES; } - (NSArray<UIKeyCommand *>*)keyCommands { return @[

iOS Swift Interrupt Keyboard Events

泄露秘密 提交于 2019-12-21 05:30:08
问题 I have problem to intercept keyboard events. I have connected my iOS with SteelSeries Free (gamepad controller) which when connected to iOS will be detected as a Bluetooth Keyboard. This is tested when I open Notes, any button presses in the gamepad will write a letter. I need to intercept this button presses and run my own functions but unfortunately I am unable to do so. I've been trying to use GCController but apparently it is not detected as Game Controller object. When I print the count,

Detect delete key using UIKeyCommand

跟風遠走 提交于 2019-12-21 03:44:09
问题 Anyone know how to detect the "delete" key using UIKeyCommand on iOS 7? 回答1: As people were having problems with Swift, I figured a small, complete example in both Objective C and Swift might be a good answer. Note that Swift doesn't have a \b escape character for backspace, so you need to use a simple Unicode scalar value escape sequence of \u{8} . This maps to the same old-school ASCII control character number 8 ("control-H", or ^H in caret notation) for backspace as \b does in Objective C.

How can I make a UIKeyCommand with the return/enter key?

隐身守侯 提交于 2019-12-03 23:35:13
问题 I'd like to make a UIKeyCommand that uses only the [return] key. So far I've tried: UIKeyCommand *selectCommand = [UIKeyCommand keyCommandWithInput:@"\n" modifierFlags:0 action:@selector(chooseSelection:)]; There's no global constant for the enter key, like there is for up, down, left, right, and escape (from UIResponder.h ): // These are pre-defined constants for use with the input property of UIKeyCommand objects. UIKIT_EXTERN NSString *const UIKeyInputUpArrow NS_AVAILABLE_IOS(7_0); UIKIT

iOS Swift Interrupt Keyboard Events

时光总嘲笑我的痴心妄想 提交于 2019-12-03 16:21:15
I have problem to intercept keyboard events. I have connected my iOS with SteelSeries Free (gamepad controller) which when connected to iOS will be detected as a Bluetooth Keyboard. This is tested when I open Notes, any button presses in the gamepad will write a letter. I need to intercept this button presses and run my own functions but unfortunately I am unable to do so. I've been trying to use GCController but apparently it is not detected as Game Controller object. When I print the count, it shows as 0. My code below. let gameControllers = GCController.controllers() as! [GCController]

Detecting continuous key presses with UIKeyCommand

人走茶凉 提交于 2019-12-03 05:58:38
问题 Is it possible to get continuous key presses? I'm using keyCommands : to intercept the arrows keys being pressed on an external keyboard, but I only get 1 call per press. I would love to get either multiple calls every X milliseconds as long as the key is held down, or calls when the key is pressed and when it’s released. Here's my code: - (NSArray *)keyCommands { UIKeyCommand *upArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputUpArrow modifierFlags:0 action:@selector(upArrow:)];

How can I make a UIKeyCommand with the return/enter key?

时间秒杀一切 提交于 2019-12-01 02:30:45
I'd like to make a UIKeyCommand that uses only the [return] key. So far I've tried: UIKeyCommand *selectCommand = [UIKeyCommand keyCommandWithInput:@"\n" modifierFlags:0 action:@selector(chooseSelection:)]; There's no global constant for the enter key, like there is for up, down, left, right, and escape (from UIResponder.h ): // These are pre-defined constants for use with the input property of UIKeyCommand objects. UIKIT_EXTERN NSString *const UIKeyInputUpArrow NS_AVAILABLE_IOS(7_0); UIKIT_EXTERN NSString *const UIKeyInputDownArrow NS_AVAILABLE_IOS(7_0); UIKIT_EXTERN NSString *const