Check multi-keys press
-
Hi, i tried to use objc
UIViewController
to 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’sCustomViewController_pressesBegan_withEvent_
will not triggered, pls help?
-
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 withui.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
vi.View().get_key_commands()
andui.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
-
last edited by
-
There are four methods you can implement:
https://developer.apple.com/documentation/uikit/uiresponder/1621134-pressesbegan?language=objc
You also have pressesEnded_withEvent_, and pressesChanged_withEvent_. Technically, pressesCancelled_withEvent_, but that's rare.
You can inspect the modifiers:
UIKeyModifierAlphaShift 1<<16
A modifier flag that indicates the user pressed the Caps Lock key.
UIKeyModifierShift 1<<17
A modifier flag that indicates the user pressed the Shift key.
UIKeyModifierControl 1<<18
A modifier flag that indicates the user pressed the Control key.
UIKeyModifierAlternate 1<<19
A modifier flag that indicates the user pressed the Option key.
UIKeyModifierCommand 1<<20
A modifier flag that indicates the user pressed the Command key.
UIKeyModifierNumericPad 1<<21
A modifier flag that indicates the user pressed a key located on the numeric keypadAlso, 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
ObjCInstance(c_void_p.in_dll(c, 'UIKeyInputRightArrow'))
But in this case, the NSString is simply equal to the constant name.
-
@JonB so….. what should i change?