Help please with keyDown Observer



  • I am trying to get the chars or keyCode value when a key is pressed. So return which key was pressed.
    I see the info["event"] NSEvent but can’t get anywhere from there.
    I tried to get an idea from the developer site to no avail.
    Is there an example file or some other help.
    Please. Thanks. jo


  • admin

    This should do it to catch keydowns in a glyph view

    from mojo.events import addObserver
    
    class testKeyDown:
        
        def __init__(self):
            addObserver(self, "keyDown", "keyDown")
            
        def keyDown(self, notification):
            event = notification["event"]
            print event.keyCode()
            print event.characters()
        
    testKeyDown()
    

    good luck!



  • hey frederik,
    I was sooo close …
    Thanks a lot for your help, working perfectly now.
    jo