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.


    Custom keyboard shortcuts

    Pythonista
    3
    7
    6799
    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.
    • JonB
      JonB last edited by

      i don't have a bluetooth kb to test this with, but I think this should now work:

      https://github.com/jsbain/objc_hacks/blob/master/keycommands.py

      Run it once, the check that there are no assertions. Then try cmd-h to see if 'hi' is printed to the console again.

      1 Reply Last reply Reply Quote 3
      • shaun-h
        shaun-h last edited by

        Still didn't work for me, are you sure you have pushed it, the code says it was changed a day ago? It errors on line 26 saying the initWith... Method was not found I change it to

        mykey=UIKeyCommand.keyCommandWithInput_modifierFlags_action_('h',UIKeyModifierCommand,btnobj.invokeAction_.method)
        

        It no longer errors, but the shortcut does nothing still.

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

          whoops, you are right, i committed but forgot to push. should be there now.

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

            It worked! Wow! This approach has so much potential.

            Thanks @JonB !!

            1 Reply Last reply Reply Quote 0
            • shaun-h
              shaun-h last edited by

              Yeah it is working now, this is awesome thanks so much.

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

                Great!

                This can get attached to anything derived from UIResponder, so you could attach it to the stash view, and it won't do anything while in the editor.

                Obviously this needs to be cleaner, check for duplicate keys, and probably should use a pure CFUNCTYPE for the imp, rather than creating a whole new objc class. I also don't love having to store a global, there are better ways to do this. It should also be possible to add a discoverabilityTitle in ios9 which pops up when holding down command. (other modifiers are also possible)

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

                  I am thinking more about using it with the builtin editor. Stash already has external keyboard support by subclassing SUITextView and supplying keyCommands which creates a new TextView class entirely. I didn't know it is possible to swizzle and change existing class's behaviour.

                  This could bring the programmable builtin editor to a whole new level. I guess it might even be possible to substitute the UITextView's delegate methods, e.g textView:shouldChangeTextInRange:replacementText:? If so, the editor could be made even more intelligent.

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