Rhino ScriptEditor: Rhino.RhinoApp.EscapeKeyPressed wrongly True

Hi,

I have a python script running directly in Rhino using the new ScriptEditor.

In a for loop i added the below

for i, element in enumerate(elements):

            if Rhino.RhinoApp.EscapeKeyPressed:
                    print("Cancelled by user.")
                    break

However it’s breaking also without pressing escape. Seems like a python bug to me. Usually works fine in C# in my compiled plugins.

EscapeKeyPressed’s neither a simple method, nor a property of RhinoApp.

I don’t know how one should work with “Events” in Python though. Register a call back function (like .onClick in JS)?

https://developer.rhino3d.com/api/rhinocommon/rhino.rhinoapp/escapekeypressed

1 Like

@sonderskovmathias did you registered the event? you first need to register a callback function for when the event is triggered:

RhinoApp.EscapeKeyPressed += escape_function

1 Like

Ahh yes, thanks! Intuitively I thought I was still using the boolean method from grasshopper.

if (GH_Document.IsEscapeKeyDown())

ofcourse I see now that it’s an event (i should never have gone out of C# and into python but im working with IfcOpenShel atm…)

I should be able to have a global bool set in python and subscribe an event on escape press to change that boolean.

1 Like