how to log RMB press during python states? [it was: "Warning: There is no hotkey for "]

   2566   8   0
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
I was experimenting with the onKeyEvent(), following the Python States documentation, but I'm facing a couple of issues.
  1. If I press a key NOT in the group, the ELSE statement is executed, but I'm getting anyway the aforementioned output error in the console, which is quite annonying.
  2. If I press the ‘s’ key, instead Houdini would exit the viewer state and switch to the Selection State, which is understandable, being ‘s’ the hotkey for that, BUT the IF statement is not getting evaluated. So you can't know if an already assigned hotkey is being pressed in your custom node viewer state.




    def onKeyEvent(self, kwargs):
        ui_event = kwargs['ui_event']
        self.key_pressed = ui_event.device().keyString()
        if self.key_pressed in ('a', 's', 'shift a', 'ctrl g'):
            # returns True to consume the event
            print('key pressed')
            return True
        else:
            print('No')
            
    
Edited by Andr - Oct. 4, 2019 03:56:14
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
The issue #1 has been fixed in 17.5, you probably just need to get an updated build.

Regarding case #2, Houdini will intercept the ‘S’ key before onKeyEvent can even see it, unfortunately the key is not overridable. The select state will be run as volatile and your state will get active again once you've done a selection. At this point the onSelection callback should be called if one is defined.
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
all right, thanks a lot for the clarifications!


Regarding 2), I just needed to call a custom function during the python state when ‘S’ is pressed.
I've found that I can temporarily clear the ‘S’ assignment during my python state (and reload it on exit)
hou.hotkeys.clearAssignments('h.pane.gview.state.volatile_select')
So now the onKeyEvent is being triggered
Edited by Andr - Oct. 3, 2019 15:45:00
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
related to 2)
https://www.sidefx.com/docs/houdini/hom/hou/UIEventDevice.html [www.sidefx.com]
I see the api provides a method for Right Mouse Button press, but again, when I click the rmb it won't trigger any event, only the context menu pops up (and won't allow any new mouse event to be logged)

    def onMouseEvent(self, kwargs):
        ui_event = kwargs['ui_event']
        print(ui_event.device().isRightButton() )

So, how to know when RMB is pressed during a python state?

thanks for any help
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
Andr
related to 2)
https://www.sidefx.com/docs/houdini/hom/hou/UIEventDevice.html [www.sidefx.com]
I see the api provides a method for Right Mouse Button press, but again, when I click the rmb it won't trigger any event, only the context menu pops up (and won't allow any new mouse event to be logged)

    def onMouseEvent(self, kwargs):
        ui_event = kwargs['ui_event']
        print(ui_event.device().isRightButton() )

So, how to know when RMB is pressed during a python state?

thanks for any help

Yea it looks like a bug. You should be able to get the mouse event when no popup menu is bound to the python state.

Can you file a new bug ?

thanks
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
Ok I opened one, should be fixed soon.
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
thanks a lot _mab_!
User Avatar
Member
7 posts
Joined: June 2016
Offline
Reviving an old post here but I think this is related to my question...
So when I right click on a geo, there's a default context menu.
Is there a way to deactivate that so i can do custom RMB events on actual geometry?
I don't have any custom context menu.
When I RMB on empty viewport space it logs in the RMB event properly though, so I know it's working the way it's supposed to.
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
Yes that's the expected behavior if you don't have any custom menu on your state.

Please file an RFE for your suggestion.

thanks
  • Quick Links