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.
Does the keyboard module has any method to send message automatically?
-
for example: put a button in the view, when the button was pressed, input some text then send the message out immediately.
(Sorry, my English is not very well, but I'm working on it :)
-
@jszsj Sorry but I don't understand "send the message out".
-
@cvp When typing in some chatting apps, the label of the button at the right-bottom corner of the keyboard will change to "Send", what I want is to call the "Send" command in python script instead of press the "Send" button
-
@jszsj understood, but when do you want this "send" to be executed, in which conditions while you are typing on the keyboard?
-
@cvp I want to trigger the "send" action by a custom button in my view
-
@jszsj But when you use a Pythonista keyboard, you don't see this send button, do you?
-
@cvp You can see the "Colors" example of keyboard, it have an ui view, there are two buttons: "Copy" and "Insert" in the view, we can use these buttons to test or add another button to do the job
-
@jszsj, if I understand what you are trying to do here:
I am pretty sure Pythonista, custom keyboard or otherwise, cannot ”click” on buttons of other applications.
-
Agree with @mikael
Edit: but, if this chat runs in a website, we could imagine that a Pythonista keyboard button executes a JavaScript which taps a web-button like, perhaps, your "send" key does
-
@mikael I'm not trying to ”click” on buttons of other applications
I think, if pythonista can trigger some kind of keyboard event, it may do the "send" job.
The label of the button at the right-bottom corner of the keyboard is dynamic, in some app it's "Done", in safari it's "Go", in the chatting app it's "Send", here's the screen snap
-
-
@jszsj and @mikael I think I did it 😅
Little keyboard script, only interesting thing is auto_return action...
You add to put the label of the button you want to simulate, like "send" in list where you see already "return" and "go"import ui 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 = 'return' iv.action = self.auto_return self.add_subview(iv) def auto_return(self,sender): o = ObjCInstance(sender) # objectivec button while True: o = o.superview() if 'KeyboardInputView' in str(o._get_objc_classname()): KeyboardInputView = o break def analyze(v): for sv in v.subviews(): if 'uibuttonlabel' in str(sv._get_objc_classname()).lower(): if 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(): # how to simulate press the return button print('ici') 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 Great job!
I'll have a try