I want to implement custom keyboard shortcut for a custom Rhino Command build in RhinoCommon


#1

I want to implement custom keyboard shortcut for a custom Rhino Command build in RhinoCommon.
Is it possible to call a command without writing it in command line, just by pressing hotkey?
I know how to trigger a button within windows form by hotkey. But this time I am not using windows form. So not sure how to do it.

If rhino custom tool bar is an option for creating new hot key then please let me know.

I mean I want to implement new hotkey for custom command I made. I could successfully use keyboard listener for Rhino in windows form and while the command is running. But Now I want to call a custom command when certain keyboard button is pressed.


(Menno Deij - van Rijswijk) #2

I suppose you could use the same keyboard listener and use RhinoApp.RunScript() when the desired shortcut is typed.


#3

Hi Menno, Happy to hear from you again !
Many thanks for helping me out last time :slight_smile:
But, I need to call a command to initiate keyboard listener. no?

Our problem is, we will not be at front of computer, we have a remote numberpad, we want to
press a number to trigger a Rhino command.

Keyboard listener is working very successfully, when I am using it within a big command.
But for example, a rhino default command I have wrote it as RhinoApp.RunScript() already as a plugin.
Now I just want to install it and I want to call the command by pressing a number in number pad, without coming to the computer. So you think this keyboard listener will work when a command is not running? OK I am going to try now.

Keyboard listener work very cool, after calling a command and while running a command, if you have keyboard listening activity it can read perfect… Do you think, without calling any command, hotkey can be implemented within rhino… I am trying , I was just very confused, I did not try yet.


(Menno Deij - van Rijswijk) #4

There should be no need to initialize it in a command, why not initialize the keyboard listener when the plug-in loads? Then it is always active.


#6

OK… then I have to see why it is not working. So when plugin loads the keyboard listener should start listening. that is exactly what I want … I am seeing what is wrong in my code.

Many thanks !
It is a big help again !
.


(Menno Deij - van Rijswijk) #7

Ok, good luck. Glad I could help


#8

without calling the command the listener does not work… After all, it is a command plugin and I am enabling the listener, within command . So even logically the listener should work only when I call the command …no?

Please let me know how to initiate a listener, just by uploading plugin.
I do not want to call any command in command line of Rhino interface.

Many thanks !


(Menno Deij - van Rijswijk) #9

There is an overridable method in the PlugIn class, called OnLoad. Initialize the listener in this method.

class MyPlugIn : Rhino.PlugIns.PlugIn
{
  protected override LoadReturnCode OnLoad(ref string errorMessage)
  {
    // initialize kb listenere here
  }
  
}


(Menno Deij - van Rijswijk) #10

By the way: are you aware that Rhino has built-in support for keyboard shortcuts? Any command name or script can be assigned to a shortcut.


(Steve Baer) #11

This is exactly what I was about to recommend. I think using keyboard listeners and running commands when certain keys are pressed is going to break other functionality in Rhino.


#12

Many thanks to Menno and Steve !

Writing inside Plugin load is not very smooth in operation and I am bit worried to use it…But good to know it. I have again learn something new from you !
I completely forgot about built-in support for keyboard shortcuts!

That will help me for some functionality, for sure…

Many thanks to both of you !
Tah