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.


    Check multi-keys press

    Pythonista
    viewcontroller keypress objcutil
    4
    42
    3991
    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.
    • yaley
      yaley last edited by

      Hi, i tried to use objc UIViewController to get key press with text field, but the problem is, if i press left arrow key first, and then press right arrow key, the right arrow key’s CustomViewController_pressesBegan_withEvent_ will not triggered, pls help?

      cvp 1 Reply Last reply Reply Quote 1
      • DOGGY
        DOGGY last edited by

        You can try to use

        key_command(sender)
        

        and

        get_key_commands()
        

        For documentation : visit here

        1 Reply Last reply Reply Quote 0
        • yaley
          yaley last edited by

          i tried it before, but thank for your help :D it does the same result

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

            @yaley said

            if i press left arrow key first, and then press right arrow key

            I guess you did not release the first press. Then perhaps you could intercept pressesChanged(_:with:)

            1 Reply Last reply Reply Quote 0
            • DOGGY
              DOGGY last edited by

              @yaley ok. How about using pygame module? It might work :

              import pygame
              screen = pygame.display.set_mode((0,0,320,320))
              while True:
                  for event in pygame.event.get():
                      if event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
                          if event.mod == pygame.KMOD_NONE:
                              print('No modifier keys were in a pressed state when this '
                                'event occurred.')
                          else:
                              if event.mod & pygame.KMOD_LSHIFT:
                                   print('Left shift was in a pressed state when this event '
                                    'occurred.')
                              if event.mod & pygame.KMOD_RSHIFT:
                                   print('Right shift was in a pressed state when this event '
                                    'occurred.')
                              if event.mod & pygame.KMOD_SHIFT:
                                  print('Left shift or right shift or both were in a '
                                    'pressed state when this event occurred.') 
              
              cvp 1 Reply Last reply Reply Quote 1
              • cvp
                cvp @DOGGY last edited by

                @DOGGY as explained here pygame is not Pure PyThon thus does not work in Pythonista

                1 Reply Last reply Reply Quote 1
                • yaley
                  yaley last edited by

                  @cvp my code is still not working

                  
                  def CustomViewController_pressesBegan_withEvent_(_self, _cmd, _presses, event):
                  	global activeKeys
                  	presses = ObjCInstance(_presses).allObjects()
                  	keyCode = presses[0].key().keyCode()
                  	
                  	activeKeys[keyCode] = True
                  	
                  def CustomViewController_pressesEnded_withEvent_(_self, _cmd, _presses, event):
                  	global activeKeys
                  	presses = ObjCInstance(_presses).allObjects()
                  	keyCode = presses[0].key().keyCode()
                  	
                  	activeKeys[keyCode] = False
                  	
                  def CustomViewController_pressesChanged_withEvent_(_self, _cmd, _presses, event):
                  	global activeKeys
                  	presses = ObjCInstance(_presses).allObjects()
                  	keyCode = presses[0].keyCode()
                  	
                  	activeKeys[keyCode] = False
                  
                  
                  cvp 2 Replies Last reply Reply Quote 1
                  • cvp
                    cvp @yaley last edited by cvp

                    @yaley why do you set your activeKeys as False in changed?

                    1 Reply Last reply Reply Quote 0
                    • DOGGY
                      DOGGY last edited by DOGGY

                      @yaley Yes, sorry, as @cvp and my tries, using pygame module is not possible in Pythonista because Pythonista doesn’t have pygame Stash also cannot

                      1 Reply Last reply Reply Quote 0
                      • yaley
                        yaley last edited by

                        @DOGGY It’s ok :)

                        1 Reply Last reply Reply Quote 0
                        • yaley
                          yaley last edited by

                          @cvp oops that’s my wrong, but after changing it to True, it’s still not working, everything turns True, let me see the documentation carefully again.

                          After the key changed, the activeKey turns True, but then it will forever True, until next keyup

                          1 Reply Last reply Reply Quote 1
                          • cvp
                            cvp @yaley last edited by cvp

                            @yaley don't forget that presses is a kind of array with eventually multiple keys thus perhaps not only check [0]

                            1 Reply Last reply Reply Quote 0
                            • DOGGY
                              DOGGY last edited by DOGGY

                              @YaleY that would be a hard one…..

                              1 Reply Last reply Reply Quote 0
                              • yaley
                                yaley last edited by

                                @cvp so what should i do now???? Can you show me the code with successful running?

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

                                  @yaley said

                                  Can you show me the code with successful running?

                                  Ho no, you are further than me. I only try to think about it.
                                  When you press the right arrow, your first key is still pressed?

                                  1 Reply Last reply Reply Quote 0
                                  • yaley
                                    yaley last edited by

                                    @cvp yes, but the problem is when the second press joined CustomViewController_pressesChanged_withEvent_() didnt run about it

                                    cvp 1 Reply Last reply Reply Quote 1
                                    • yaley
                                      yaley last edited by

                                      @cvp You’re method is correct, just i am stupid, i typed wrongly, i set the variable to True in the pressesEnded def

                                      XD

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

                                        @yaley right, just tested

                                        1 Reply Last reply Reply Quote 0
                                        • yaley
                                          yaley last edited by

                                          Wait no, why??? Why my first test is correct and then the second test is not working?????

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

                                            @yaley for me, changed not called
                                            If you change something in a created class, restart Pythonista

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