Python Viewer State and Hotkeys

   4337   14   3
User Avatar
Member
162 posts
Joined: May 2015
Offline
Greetings everybody

I am wondering if it is possible to disable hotkeys while in a custom python viewer state. Here is my problem, I am trying to use the “t”, “r” and “e” onKeyEvent in my object level python viewer state, but the viewport hotkeys seem to catch them first and it switches to the translation, rotation or scaling tools. I tried with the onKeyTransitEvent and it does catch the “key down” event and I then return True to consume the key transition, but the viewport still switches to the corresponding transformation tool.

Would there be a way to use those keys or do hotkeys have priority over viewer states key events?

Thanks in advance for you help
User Avatar
Staff
445 posts
Joined: Feb. 2018
Offline
Unfortunately, some hotkeys like the ones you mention cannot be overridden by python states. The hotkey architecture is currently being reworked to fix these kinds of problems.
User Avatar
Member
162 posts
Joined: May 2015
Offline
All right, thanks for the answer mabelzile!
User Avatar
Member
34 posts
Joined: July 2015
Offline
mabelzile
Unfortunately, some hotkeys like the ones you mention cannot be overridden by python states. The hotkey architecture is currently being reworked to fix these kinds of problems.

Hi @mabelzile,

Is it still the case?

Thanks
User Avatar
Staff
445 posts
Joined: Feb. 2018
Offline
Akelian
mabelzile
Unfortunately, some hotkeys like the ones you mention cannot be overridden by python states. The hotkey architecture is currently being reworked to fix these kinds of problems.

Hi @mabelzile,

Is it still the case?

Thanks

Yes it still the case.
User Avatar
Member
83 posts
Joined: Feb. 2020
Offline
mabelzile
Unfortunately, some hotkeys like the ones you mention cannot be overridden by python states. The hotkey architecture is currently being reworked to fix these kinds of problems.

Is this still the case
User Avatar
Member
5 posts
Joined: Oct. 2021
Offline
is this still the case
User Avatar
Member
83 posts
Joined: Feb. 2020
Offline
artchapter
s this still the case

I'm pretty sure this is still the case :/
User Avatar
Member
18 posts
Joined: Nov. 2018
Offline
this is now possible. in your createViewerStateTemplate do the following:

state_typename = kwargs["type"].definition().sections()["DefaultState"].contents()

menu = hou.ViewerStateMenu(state_typename + "_menu", state_label)
del_key = su.hotkey(state_typename, "delete_point", "Del", "delete selected points")
menu.addActionItem("delete_point", "delete selected points", hotkey=del_key)
template.bindMenu(menu)

this will override the delete key ("Del") when in your viewer state. "delete_point" is the key code and corresponds to the key code in "menu.addActionItem". when the user hits the delete key, the user will call what would normally be called when selecting the item from the right mouse button menu. "delete selected points" is the description, and and can be anything you would like. the important part is to use the correct key string, "Del" for delete, "UpArrow" for up arrow, "ENTER" for enter, etc...

su.hotkey is part of a library that is already imported in your viewer sate. it handles a lot of what you could be doing manually as shown in the docs: https://www.sidefx.com/docs/houdini/hom/state_menus.html#hotkeys [www.sidefx.com]

hope that helps
User Avatar
Member
162 posts
Joined: May 2015
Offline
Thank you so much for your answer @playBalster!

I will test this as soon as I can
User Avatar
Member
4 posts
Joined: Aug. 2022
Offline
cval
Thank you so much for your answer @playBalster!

I will test this as soon as I can

Hey @cval, were you able to make it work?
From my testing I can’t override these specific shortcuts.

My solution is to remove these shortcuts using the hotkeys python module and then onExit to assign them back, but it’s not good practice I suppose.
User Avatar
Member
373 posts
Joined: June 2023
Offline
Is there an easy way to know which hotkeys are "free to use" by a Python state?
Edited by kodra - Dec. 16, 2023 11:29:21
User Avatar
Member
4 posts
Joined: Aug. 2022
Offline
kodra
Is there an easy way to know which hotkeys are "free to use" by a Python state?
I did a little run through all the characters and the ones who seem to be "locked" are:
d (Display options)
e (Scale tool)
j (Modify Channels)
r (Rotate Tool)
s (Volatile Select Mode)
t (Move Tool)
w (Wireframe)
And also these special characters ` \ ?

I wish we could override these in python states!
User Avatar
Member
8832 posts
Joined: July 2007
Offline
yonatanbary
kodra
Is there an easy way to know which hotkeys are "free to use" by a Python state?
I did a little run through all the characters and the ones who seem to be "locked" are:
d (Display options)
e (Scale tool)
j (Modify Channels)
r (Rotate Tool)
s (Volatile Select Mode)
t (Move Tool)
w (Wireframe)
And also these special characters ` \ ?

I wish we could override these in python states!
Are you talking about H20?

while I don't have much experience with Pyhon States limitations I'd find it odd if these were still an issue especially since Car Rig Python State in H20 uses hotkeys like WASD for movement and they seem to work
Edited by tamte - Dec. 17, 2023 16:38:25

Attachments:
carrig_state_shortcuts.gif (10.4 KB)

Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
373 posts
Joined: June 2023
Offline
I tried to set move tool's hotkey to G (like in Blender). That breaks almost all the built-in Python states, since they all use G.

Ideally it shouldn't break Python states, unless the specific state has transform handle (so move tool makes sense).

I still don't know when Python state's hotkeys take precedence over Houdini's tho.
Edited by kodra - Dec. 17, 2023 22:21:02
  • Quick Links