Hello,
I’m trying to implement the simple functionality of detecting a mouse button press and release and pulling my hair out. It seems Rhino.UI.MouseCallback has all the functionality I need for this but I can’t seem to get any code working that does anything “OnMouseDown” or “OnMouseUp” in Rhino8.
I’m sure I’m overlooking something obvious, I guess I’ve had my head in the sand for too long on this and now I’m just completely stuck. I’ve had success with mouse events in GH components I’ve written but just stumped in Rhino right now.
I found this code circa 2018 that seemed like a simple enough python implementation but only the else statement of the definition “TestSampleMouseCallback” prints its statement. (And quite honestly, I may just be misunderstanding the intent of this code but I expect it to print the button name on a Mouse click but that doesn’t seem to happen)
import System
import Rhino
import scriptcontext as sc
class SampleMouseCallback(Rhino.UI.MouseCallback):
def OnMouseDown(self, e):
print "OnMouseDown", e.Button
def TestSampleMouseCallback():
if sc.sticky.has_key('TestSampleMouseCallback'):
callback = sc.sticky['TestSampleMouseCallback']
if callback:
callback.Enabled = False
callback = None
sc.sticky.Remove('TestSampleMouseCallback')
else:
callback = SampleMouseCallback()
callback.Enabled = True
sc.sticky['TestSampleMouseCallback'] = callback
Rhino.RhinoApp.WriteLine("Click somewhere...")
if __name__ == "__main__":
TestSampleMouseCallback()
I’m after having a cross platform code solution to simply test if a mouse button was pressed or released and then DoSomething().
Any leads are greatly appreciated, thank you!