Tool Forwarding Of Keypresses


I was wondering if it is possible to send keys from a tool to renoise
so that pressing the arrow keys would move the cursor as usual even though
the tool is open. Then the tool could handle the keys it would like and let
the user interact with renoise as usual without having to close the tool.

You can set a keyhandler in your tool by pointing to it within the last parameter of the tool dialog open method.
If you simply quit the keyhandler function with “return key”, the key contents are passed to renoise.
You could in that regard perhaps even modify the key contents and make renoise perform another action if returning a different keycombo than received.
If that works, you can however only do that if the user has striked a key.

function key_handler(dialog,key)  
 if == "down" then  
 if start_instrument + created_range < then  
 start_instrument = start_instrument + 1  
 -- The scrolled variable is to prevent feedback loops  
 scrolled = 1  
 scrolled = nil  
 if == "up" then  
 if start_instrument > 1 then  
 start_instrument = start_instrument - 1  
 scrolled = 1  
 scrolled = nil  
 return key  

It isn’t possible to actively send keys directly into Renoise from your tool, ie. your can’t send a string of key combos into Renoise in order to trigger certain functions. But it is possible to handle key events from your tool GUI in a more passive fashion. You do this by creating a key handler function, and then passing this key handler as an argument into your tool’s show_custom_dialog() function. This will cause any key events to be sent through your custom key handler function, where you can then decide how to handle things. You have the option to intercept the key event and do something with it, or to simply return it back to Renoise where it will be handled in the default way (but not necessarily in the way you might expect…)

If you want a nice example of this, you can download the XRNX Starter Pack here:

Check out the “Example Tool GUI” tool, which has a “Keyboard Events” example that shows how to grab the key events and do something with them.

Unfortunately, you won’t be able to return the arrow key events back to Renoise and have them move the pattern cursor. This is because while your tool GUI is open and focused, the pattern editor itself is not focused, and therefore the arrow key events will never reach it.

However, you can be a bit clever here and intercept the arrow key events in your tool, and then manually move the pattern editor position up or down (or anywhere you want, really). I’ve made a quick modification to the tool I mentioned above, which just strips out the key handling functionality and shows a simple method for moving through the pattern editor from your tool’s GUI:

3124 org.illformed.KeyHandlerExample_Rns280_V1.xrnx

Hopefully this gives you enough ideas to take it further and improve the functionality for your own tools.

Edit: vV beat me to the punch, but hopefully both our posts will be helpful.

@Vv That was just what I was looking for thanks! It seems it works for some keys only though,
Space and CTRL-t work but the arrowkeys or CTRL arrows don’t.

@Dblue Thanks for the detailed explanation! I was looking at this and started the approach of
manually recreating the behaviour I was after, but then thought that there must be a better
way. I guess I could do this for the keys that do not get caught by renoise when using
Vv’s method, if I need to.

I figured a way to do exactly that…

Yep. Quite a few similar things out there, but I think we both know I was speaking of native functionality here, not relying on 3rd party stuff :P