Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How to get key pressing in scene module?
-
https://www.swiftbysundell.com/tips/handling-keyup-and-keydown-events/
This is now possible in iOS 13.4, however, someone will need to translate this to ObjC. @cvp? @mikael? I can give it a shot, but not until next week.
-
sorry, but that website was JS or Java…..
-
It is swift, but it is possible to convert that to objc_util
-
@JonB I would like to help but it seems to be a little bit too complex for me, I guess it is better to wait that you find the time to do it. Sorry, but happy to discover this new feature from Apple
-
I believe we just need to have a custom view controller that implements
pressesBegan_withEvent(presses, event)
Where presses is an NSSet of UIPresses. You can use
presses.allObjects()
to convert a NSSet to array...from.there,key
. -
E.g.
presses.allObjects()[0].key().keyCode()
-
@JonB what is
pressesBegan_withEvent(presses, event)
-
@yaley said
what is pressesBegan_withEvent(presses, event)
A method to implement to the custom UIViewController, this is a new standard method called when a key goes down
-
@cvp so the whole code is like….
objc.ObjCClass("UIViewController").pressBegan_withEvent(presses, event)
that? -
@yaley Ho no. This is not so simple. You have to create a custom UIViewController and configure the used methods and protocols. And one method could be the new one which should be called at each key down
You could check this topic where a such ViewController is used with a user method
CustomViewController_touchesBegan_withEvent_
Only to show it is not so easy
-
@cvp ok Thanks for your helping!
-
@yaley Sorry that I can't help more...
-
@cvp oh sorry, i have another question, what are presses and event?
Is presses like [“a”, “b”, “c”] and is event like a function? -
@yaley presses is a set of UIPress objects and event is an UIPressesEvent object. Both are ObjectiveC classes
-
@yaley see Apple doc UIPressesEvent and UIPress
-
@cvp thank you ❤️ you helped me a lot
-
@yaley I hoped that some code like this could work, but not true. Thus, sure this is too complex for me. We will wait availability of @JonB
from objc_util import * import ui UIViewController = ObjCClass('UIViewController') # Some callback definitions used by create_objc_class def pressesBegan_withEvent(_cmd, _presses, _event): print('pressesBegan_withEvent') presses = ObjCInstance(_presses) # The main class... class MyView(ui.View): def __init__(self): super().__init__(self) self.background_color = 'gray' @on_main_thread def initialize(self): v = ui.View() v.frame = self.frame tf = ui.TextField() tf.frame = (10,10,200,32) v.add_subview(tf) vo = ObjCInstance(v) #print(vo) #print(dir(vo)) # set up the custom view controller methods = [pressesBegan_withEvent] protocols = [] CustomViewController = create_objc_class('CustomViewController', UIViewController, methods=methods, protocols=protocols) cvc = CustomViewController.alloc().init() cvc.view = vo # internal scheming... self_objc = ObjCInstance(self) self_objc.nextResponder().addChildViewController_(cvc) self_objc.addSubview_(vo) cvc.didMoveToParentViewController_(self_objc) tf.begin_editing() if __name__ == '__main__': v = MyView() v.present('fullscreen') v.initialize()
-
@cvp it doesn’t work….. but really thanks for your helping
-
-
I don't have an iOS device with me for a few more days...but I suspect this only works with Bluetooth keyboard, and in view controllers without textfields. If you begin_editing, the textfields will become first responder, and steal any keystrokes.