How to know which key triggered a GetObject() cancel

Hi, working on a python script that makes use of UI.Custom.GetObjects()

During the GetObjects() command, if the user hits scape button, I get GetResult.Cancel
If the user clicks mouse right button, I also get GetResult.Cancel

Could someone give me some guidance on how could I know which key the user used for cancelling the command?

I’m having a very weird problem with methods from NodeInCode Namespace. With any of them. They stop working for an Unknown reason, if and only if, a method from that namespace is called after the user cancels a command using ESC button. Everything works fine if command cancel is triggered by right mouse click, or hitting Enter… until the user uses ESC button.

From that point in advance NodeInCode methos stops working even if I use them in other python scripts, as long as i’m in the same Rhino session.

I’m aware that the case i’m describing is quite alambicated, and probably difficult to replicate in other circumstances. It’s part of a larger script, some MAYBE there is some important detail that i’m not explaining to depict the condition for the error to happen, but i’m quitec confident that the description isolates the problem. SO, I will not expect that mcneel will try to solve this “weird behaviour”.

It would be enought for me to know how I can be aware if a “command cancel” has been triggered by ESC click, so I can prevent the code to follow from the problematic logic branch.

Any advice will be welcomed. Apologies if the question is confusing, I did my best.

There’s a couple of things you could try, one of them is to subscribe to the EscapeKeyPressed event.

This will be triggered when the user presses Escape.
Another is that the right-mouse button is equivalent with the Enter key in Rhino with default settings. But, if you don’t set .AcceptNothing(True) on your Rhino.Input.Custom.GetObject instance, giving Enter/RMB will cancel the command.

As for the NodeInCode namespace - I’m not familiar with that so I can’t comment.

1 Like

I decides to avoide using NodeInCode, I was interested on meshsurface component from GH but finally I implemented a custom function for the job since It was not a great overtake. It has the additional annoyance that It requieres GH to be loaded. Is great to have all the cool GH components available , but It comes with some inconveniences (being the apparent bug I meet with, a no go, at least for the time being. Fingers crossed)
Thanks for the pair of tricks. Subcribing to keyboard events will be definitevely a nice touch for the UX of the tool i’m working on.