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.
Button like function key in pythonista keyboard
-
pls. find screenshot
-
@Andrey your link does not work, I get https://imgur.com/a/q5b65jd
-
-
@Andrey I see that you have inserted f1 then a new line, that's exactly what keyboard.insert_text('f1\n') does.
What is the problem?
Do you mean that "enter" is not "\n"? You 're right because you use this keyboard in Pythonista console but if you use it in another app, like mail, enter or \n is the same -
@cvp
Is a way to press "enter" in Pythonista console via any code? -
@Andrey Now, sorry, I only understand your request. No way with Python but perhaps with ObjectiveC.
Try this code with only one key-keyboard. It works.
For your info, the code simulates you press the standard Pythonista 'return' button of the last row.import ui from functools import partial import keyboard from objc_util import * class MyView(ui.View): def __init__(self, *args, **kwargs): super().__init__(self, *args, **kwargs) self.background_color = 'white' iv = ui.Button() iv.border_width = 1 iv.frame = self.bounds iv.title = 'F1' iv.action = self.Fkey #iv.action = self.auto_return self.add_subview(iv) def Fkey(self, sender): keyboard.insert_text(sender.title) ui.delay(partial(self.auto_return,sender),0.0) def auto_return(self,sender): global ylastrow o = ObjCInstance(sender) # objectivec button while True: #print(o._get_objc_classname()) o = o.superview() if 'KeyboardInputView' in str(o._get_objc_classname()): KeyboardInputView = o break ylastrow = -1 def analyze(v): global ylastrow for sv in v.subviews(): #print(sv._get_objc_classname()) #print(sv.text()) if 'uibuttonlabel' in str(sv._get_objc_classname()).lower(): if str(sv.text()).lower() in ['tab']: b = sv.superview() #print(sv.text(), b.frame().origin.x, b.frame().origin.y) ylastrow = int(b.frame().origin.y) elif str(sv.text()).lower() in ['return','go']: b = sv.superview() if 'uibutton' in str(b._get_objc_classname()).lower() or 'ckbkeybutton' in str(b._get_objc_classname()).lower(): #print(sv.text(), b.frame().origin.x, b.frame().origin.y) if int(b.frame().origin.y) != ylastrow: continue # how to simulate press the return button UIControlEventTouchUpInside = 255 b.sendActionsForControlEvents_(UIControlEventTouchUpInside) return True ret = analyze(sv) if ret: return True analyze(KeyboardInputView) def main(): v = MyView() if keyboard.is_keyboard(): keyboard.set_view(v,'expanded') if __name__ == '__main__': main()
-
@cvp
Thank You! I will look at the code. If it works next step for me to add it to our Pythonista keyboard. Is it possible? If we have to set up sending "Enter" for several keys only or "Enter" will send every times? -
@Andrey Sure it is possible to add this code to your keyboard.
For keys which need to generate an automatic return, and only for them, in their action function, add at the end of the functionui.delay(partial(self.auto_return,sender),0.0)
-
@cvp
Hello! Thank You a lot! It works. -
@Andrey 😅