here is more detail, another member messaged me privately and i typed it out, so here it is for anyone else who is stuck:
I think the tricky part to understand about this is that you must have created a menu action for this to work. they keys you want to override, when pressed must perform an option you have added to a menu action.
to create a menu action and a hotkey for that action add the following into the template that exists at the end of every viewer state:
def createViewerStateTemplate():
state_typename = kwargs.definition().sections().contents()
state_label = "My State Lable"
state_cat = hou.sopNodeTypeCategory()
menu = hou.ViewerStateMenu(state_typename + "_menu", state_label)
s_key = su.hotkey(state_typename, "my_action", "S", "perform my action")
menu.addActionItem("my_action", "perform my action", hotkey=s_key)
template.bindMenu(menu)
You must also have a menu item that will perform the thing you want your key to perform. this goes alongside the other callbacks in your viewer state. here is the doc page on menu actions:
https://www.sidefx.com/docs/houdini/hom/state_menus.html [
www.sidefx.com]
def onMenuAction(self, kwargs):
menu_item = kwargs
if menu_item == "my_action":
self.myAction()
myAction should contain the logic you want to happen when you press the s key. i'm not fully sure "S" is the correct string for the s key so you might have to dig around to find out what that is. i think it is correct though. the lines important for us in the template from above are:
menu.addActionItem("my_action", "perform my action", hotkey=s_key)
this will allow your menu to function. you should be able to click the RMB when in the viewer state and get a menu with an option called "perform my action". "my_action" is the string used to identify the action. this is used in onMenuAction. hotkey=s_key lets the user perform that action by pressing the key you set up in the previous line in the template from above:
s_key = su.hotkey(state_typename, "my_action", "S", "perform my action")
"S" is the key code for the s key. in the example i posted, "Del" is the key code for the delete key. the other parameters you should know.
like i stated in the beginning, the caveat of this is that ya gotta set up menu actions. it is not a huge caveat, considering you may want the user to be able to choose that action from a dropdown anyway. but still it is more work and you might not want the user to do that for some reason.
hope that helps.