Q100118: Setting custom keyboard shortcuts in Nuke 9 and 10
SUMMARY
Due to changes with how Nuke handles shortcuts, custom hotkeys set up for Nuke 8.0 earlier may not work in Nuke 9.0 or above.This article explains what has changed and how you can get your hotkeys to work in Nuke 9.0 and above.
MORE INFORMATION
Nuke 9.0 and 10 use a new shortcut system which has a context for when the shortcut is active. The default context is to apply the shortcut to the whole Nuke window.
This can lead to problems if you set a custom hotkey to create a node in the nodegraph that uses a key that has an existing shortcut elsewhere - e.g. the W, H or R, G, B and A keys in the viewer. If you don't include a context then when the mouse is over the viewer there will be 2 shortcuts using the same letter, which means that neither will run and Nuke will print a "Ambiguous short error" message in the terminal or command prompt.
To avoid this problem, Nuke's menu.addCommand() function has a new argument in Nuke 9.0 and 10.0 called "shortcutContext" to say where the shortcut should run. It has 3 possible values 0=Window, 1=Application, 2=DAG/nodegraph. So an example command to create a custom write gizmo in Nuke 9.0 or 10.0 would look something like
toolbar.addCommand('MenuLocation', 'nuke.createNode("MyWriteGizmo")', 'w', shortcutContext=2)
Please note that this argument won't be recognised by Nuke 8.0 or earlier so if you add the line to your menu.py file it will prevent Nuke 8.0 or earlier from launching. To work around this you can use the following in your menu.py
More information about assigning hotkeys and customising Nuke's menus is available in the Nuke Python Developers Guide chapter on Customising the UI.
if nuke.env['NukeVersionMajor'] < 9 :
toolbar.addCommand('MenuLocation', 'nuke.createNode("MyWriteGizmo")', 'w')
else:
toolbar.addCommand('MenuLocation', 'nuke.createNode("MyWriteGizmo")', 'w', shortcutContext=2)
FURTHER READING
Keywords: Nuke, shortcut, hotkey, customisation, customization
Comments