Check multi-keys press
Hi, i tried to use objc
UIViewControllerto get key press with text field, but the problem is, if i press left arrow key first, and then press right arrow key, the right arrow key’s
CustomViewController_pressesBegan_withEvent_will not triggered, pls help?
@cvp no it’s my wrong again xD They’re absolutely no difference before, lol
@cvp I’ve already changed it, read it again :D The difference is
Wait, um, after i added
print()the pressesChange is not activating
@yaley ok. And did you trace, sure that changed def is called?
Sorry: was typing while your previous post was coming
@cvp i dont think that that def was called :(
@yaley but do you really need it? The doc says it is called if you change something in your key press, like force. If you know which key is down and up, and when, you have all you need, haven't you?
Yep! Maybe…. No need!
@cvp But the main problem is just when arrow keys will happen, just like umm i give you an example:
I am detecting keys with
ui.Textfield()And now i start pressing left arrow key. So in the input it goes left ( the selection bar ), but if the right arrow keys joined the right arrow key, the selection bar of input still goes left.
And, also, can
ui.View().key_command(sender)detect keyup? if can, then i can make
@cvp can it?
This post is deleted!last edited by
@yaley sorry, was driving to France for some days, not able to answer
There are four methods you can implement:
You also have pressesEnded_withEvent_, and pressesChanged_withEvent_. Technically, pressesCancelled_withEvent_, but that's rare.
You can inspect the modifiers:
A modifier flag that indicates the user pressed the Caps Lock key.
A modifier flag that indicates the user pressed the Shift key.
A modifier flag that indicates the user pressed the Control key.
A modifier flag that indicates the user pressed the Option key.
A modifier flag that indicates the user pressed the Command key.
A modifier flag that indicates the user pressed a key located on the numeric keypad
Also, to check for special characters, you would look at charactersIgnoringModifiers, and check for special strings from https://developer.apple.com/documentation/uikit/uikeycommand/input_strings_for_special_keys?language=objc
for example 'UIKeyInputRightArrow'
(Convert to str before comparing).
Technically, when looking at apple docs, in this case then consts are defined as NSString *, so the way you get the value is
But in this case, the NSString is simply equal to the constant name.
@JonB so….. what should i change?