Shortcut for a macro?

Dear Klayouters,
I would like to assign a keyboard shortcut for a (python/ruby) macro that I have created. Can you give me a hint on how to do this? I tried to find a solution by going through the API, but could not find anything suitable for this purpose.

Thanks for help!

Antti

Comments

  • edited May 2016

    Found the solution - python example below. Markdown seems not to work for code blocks?


    import pya win = pya.Application.instance().main_window() def keyfun(): print("key pressed") pya.QMessageBox.information(None, "Message", "Key pressed.") keyseq = pya.QKeySequence("K") shortcut = pya.QShortcut(keyseq, win); shortcut.activated(keyfun)
  • edited November -1
    I was blind: of course the intended way to do this is through the macro properties dialog, where a keyboard shortcut can be defined!
    Anyways, the above example shows how to do it with code.
  • edited May 2016

    Well, maybe not blind ... but creative :-)

    Thanks for sharing the sample. You can format it as code by prepending four blanks for every code line (that's Markdown markup). That is in particular important for Python.

    Thanks,

    Matthias

Sign In or Register to comment.