Can Plugins Create Key Bindings?
-
I looked in the SketchUp documentation and I can't find what I'm looking for so I thought I would come here.
What I want to do is bind a custom ruby script to a specific key. For example, I want to bind the F8 key so that when it is pressed a window comes up and says "Congrats, you pressed F8!". Is this possible? If so, what is the API call?
Thanks.
-
it is not possible. keyboard shortcuts are user decision.
-
If you write a tool that messes with other people's shortcuts then it's a shortcut to becoming 'Mr Unpopular 2012'.
You might be able to do it on a PC given a convoluted Registry hack to rewrite 'HKEY_CURRENT_USER\Software\Google\SketchUp8\Settings' key/values... BUT even then, unless it's been run before Sketchup ever starts at all, the change will only be apparent after a Sketchup restart.However, if you simply want to spot which key has been pressed/release then look at the Tool class - for that's how keys are assigned to functions in a Tool itself...
http://code.google.com/apis/sketchup/docs/ourdoc/tool.html#onKeyDown
http://code.google.com/apis/sketchup/docs/ourdoc/tool.html#onKeyUp -
Here is what I eventually figured out. You can create a ruby script, add it to the plugins menu and then create a shortcut that references that script. However, to create the shortcut you have to go into the menu Window > Preferences > Shortcuts, search for the script and then add it that way.
So to recap, yes it is possible to bind scripts to keys, however you can't do it with another script. Adding shortcuts can only be done by the user it seems. So now you know.
-
Of course any user can set a Shortcut Key to any 'tool' [native or scripted], provided that it has an entry that you can access through the dialog's [filtered] list, compiled from the menus and context-menus [being 'active' items as you try to set it, e.g. 'Reverse' for faces is not listed as a potentially key-able item unless you have a face preselected before you open Preferences].
But your original question suggested you wanted to do it 'in code', which is not possible [or at least practically so].
-
Pls move to Developers forum.
Advertisement