iOS Question iOS keypress override

simonwilliamson

Member
Licensed User
Is it possible to utilize the iOS function
override func pressesBegan(_ presses: Set<UIPress>,with event: UIPressesEvent?)
from within B4i so that my app can pickup physical keyboard key presses?
 
Ideally it would be the root of the B4xMainPage (B4XView) although no controls on the 1 page that require this feature have 'focus' so it could be something else if required. Currently in B4i I am having to monitor the TextChanged handler of a textbox hidden off screen to pick up key presses which means I can't pick up non-visible characters like arrow keys and has recently started causing a lag in keypress responses for some reason.
 
Upvote 0
I haven't tested it with physical keyboard, so please try it yourself:
Code: Copy
#if OBJC
@end
@interface B4IPanelView  (presses)
@end
@implementation B4IPanelView  (presses)
- (void)pressesBegan:(NSSet<UIPress *> *)presses 
           withEvent:(UIPressesEvent *)event {
    NSLog(@"presses: %@", presses);
}
#End If

It adds this event to all panels. Check the logs.
 
Upvote 0
Indeed it does work, thank you!
However is it possible to apply the trigger to a specific panel (or control) rather than all the application panels as it stops keypresses going to all the textboxes and therefore nothing can be typed into them.
 
Last edited:
Upvote 0
Try this:
Code: Copy
Private Sub Root_ButtonPresses(Presses As Object)
    Log("event: " & Presses)
End Sub

#if OBJC
@end
@interface B4IPanelView  (presses)
@end
@implementation B4IPanelView  (presses)
- (void)pressesBegan:(NSSet<UIPress *> *)presses 
           withEvent:(UIPressesEvent *)event {
    NSLog(@"presses: %@", presses);
    [B4IObjectWrapper raiseUIEvent:self :@"_buttonpresses:" :@[presses]];
    [super pressesBegan:presses withEvent:event];
}
#End If
 
Upvote 0
Hi Erel,
The typed characters are now appearing in the textboxs but the Root_ButtonPresses event never triggers. Is there some code I can put in the NSLog message that will print the event's name just in case it isn't Root?
Also this new code seems to quadruple the NSLog message every time a key is pressed.
 
Upvote 0
Back
Top