Changing a Boolean when a key is pressed.
Does anyone know how I would be able to change a Boolean when a key is pressed on a keyboard?
15 Replies
@Coach thought I should ping on behalf of @bobtheguy_32392
Can you give any more information?
macOS or iOS? Is this to do with a text box or just a generic keypress? Do you want it to happen outside the application if on macOS?
You donβt need to ping coaches 6 minutes after the post was created.
So basicly if i were to give more information, say you were on an ipad with a keyboard attcehd to it, how would i be able to change a Boolean if i were to press one of the keys on the keyboard-? (I hope this gives some more information)
SwiftUI or UIKit?
SwiftUI
Would this work?
https://developer.apple.com/documentation/swiftui/view/keyboardshortcut(_:modifiers:)
Apple Developer Documentation
keyboardShortcut(_:modifiers:) | Apple Developer Documentation
Defines a keyboard shortcut and assigns it to the modified control.
Itβs the βSwiftUIβ way to do it.
I think it would work, Thank you!
The other option would be something like this:
Alright, thank you for 2 different options! π
A few more options if needed as well:
https://stackoverflow.com/questions/59797650/swiftui-ios-how-to-capture-hardware-key-events/59798172#59798172
Stack Overflow
SwiftUI iOS - how to capture hardware key events
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 keyb...
One of them should hopefully work for your use case.
Wow, thank you for all the options man! it's really appreciated.
Bro just being utterly flabbergasted at the help you can receive through this server