omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    function keyboard
    2
    15
    197
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Andrey last edited by

      Hi Team!
      We have our owner keyboard and would like to have buttons like function key. For example F1, so if user press F1 - "f1"+Enter should be done to send "f1" to app.
      We use command: keyboard.insert_text('f1')
      Question.. Is it possible to add "enter" command without user press "Enter".
      keyboard.insert_text('f1\n') is not working
      Thank you.

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @Andrey last edited by

        @Andrey If external keyboard, see https://github.com/zrzka/blackmamba

        A 1 Reply Last reply Reply Quote 0
        • A
          Andrey @cvp last edited by

          @cvp
          no, it is not external keyboard

          cvp 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @Andrey last edited by cvp

            @Andrey so, where do you want to have your F1 key?
            Do you have an user keyboard, using keyboard module of Pythonista?
            If yes, keyboard.insert_text('\n') works correctly
            Which app would receive "F1"?

            A 1 Reply Last reply Reply Quote 0
            • A
              Andrey @cvp last edited by

              @cvp
              Yes we have an user keyboard, using keyboard module of Pythonista.
              when we put keyboard.insert_text('\n') it just move cursor to the next row, but we need to send f1 to console.

              A 1 Reply Last reply Reply Quote 0
              • A
                Andrey @Andrey last edited by

                pls. find screenshot

                https://file.io/Ctw36Js0CR7A

                cvp 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @Andrey last edited by cvp

                  @Andrey your link does not work, I get https://imgur.com/a/q5b65jd

                  A 1 Reply Last reply Reply Quote 0
                  • A
                    Andrey @cvp last edited by

                    @cvp https://file.io/rt7l3XnGtWap

                    cvp 1 Reply Last reply Reply Quote 0
                    • cvp
                      cvp @Andrey last edited by cvp

                      @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

                      A 1 Reply Last reply Reply Quote 0
                      • A
                        Andrey @cvp last edited by

                        @cvp
                        Is a way to press "enter" in Pythonista console via any code?

                        cvp 1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @Andrey last edited by cvp

                          @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()
                          
                          A 1 Reply Last reply Reply Quote 0
                          • A
                            Andrey @cvp last edited by

                            @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?

                            cvp 1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @Andrey last edited by cvp

                              @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 function

                              ui.delay(partial(self.auto_return,sender),0.0)
                              
                              A 1 Reply Last reply Reply Quote 0
                              • A
                                Andrey @cvp last edited by

                                @cvp
                                Hello! Thank You a lot! It works.

                                cvp 1 Reply Last reply Reply Quote 0
                                • cvp
                                  cvp @Andrey last edited by

                                  @Andrey 😅

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post
                                  Powered by NodeBB Forums | Contributors