Currently dealing with an interactive tool , but quite stuck with windows.form.keys. Which should be a small part but I am not known to the associated class, methods and delegates. in RhinoCommon for keyboard event… no example so far online and it is hard to locate the right classes and methods. Only one Python code found and I am not able to convert it, because it does not show classes and methods of RhinoCommon…
I mean keyboard events from Rhino side. I need to implement “enter” press after some draw operation interactively, but I should not get out of the command, by that enter pressing. So I know, I will need System.Windows.Forms.Keys.Enter, from Windows side. But I am not aware of associated Rhino class just for this event handle.
But unfortunately I could not find related event args for keyboard in c# dot net RhinoCommon.
. I do not want to use windows form buttons in the process… I want to do it un-interrupted without any windows form buttons hence, want to know how you would write those few lines to call KeyboardCallBackEvent Args? I know these name KeyboardCallBackEvent Args does not exist in Rhino common, I wrote it comparing mouseCallBackEventArgs
in short my question is, how you would relate System.Windows.Forms.Keys.Enter to event args for keyboard inside RhinoCommon.
Only sample found by Steve as below written in Python, again he used form button, I do not want to use for keyboard event handle. A small sample or few lines of code to deal with keyboard event will be a big help. Many thanks !
import Rhino import System.Drawing import System.Windows.Forms import scriptcontext class Form1(System.Windows.Forms.Form): def __init__(self): self.InitializeComponent() def InitializeComponent(self): self.SuspendLayout() self.ClientSize = System.Drawing.Size(250, 102) self.Controls.Add(self._button) self.KeyPreview = True seljf.Text = "Press J or K" self.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow self.KeyDown += self.OnKeyDownEvent self.Closing += self.OnClosingEvent self.ResumeLayout(False) def OnKeyDownEvent(self, sender, e): left = e.KeyCode == System.Windows.Forms.Keys.J right = e.KeyCode == System.Windows.Forms.Keys.K if left or right: amount = 0.1 if right: amount = -0.1 viewport = scriptcontext.doc.Views.ActiveView.MainViewport z = viewport.ConstructionPlane().ZAxis viewport.Rotate(amount, z, Rhino.Geometry.Point3d.Origin) scriptcontext.doc.Views.Redraw() finish = e.KeyCode == System.Windows.Forms.Keys.Escape finish = finish or e.KeyCode == System.Windows.Forms.Keys.Enter if finish: self.Close() e.Handled = True def OnClosingEvent(self, sender, e): Rhino.Input.Custom.GetBaseClass.PostCustomMessage("exit") f = Form1() f.Show(Rhino.RhinoApp.MainWindow()) gs = Rhino.Input.Custom.GetString() gs.SetCommandPrompt("press escape to exit") gs.AcceptCustomMessage(True) gs.Get() if not f.IsDisposed: f.Close()