Custom Shortcuts?

I’ve noticed the Sketchup.get_shortcuts method, but did not found anything to set a shortcut for my own command. It seems that this can only be done manually in Preferences. I know setting Shortcuts can get a bit finicky, especially if there are conflicts, but so far it doesn’t seem offered in the API. Is there any way I’m missing, that isn’t meddling with registry values?

(1) Fundamentally, assigning a shortcut (keyboard accelerator,) is an end-user function. This is likely why it has not yet been exposed to the API.

(2) If it were, there would be some etiquette rules that need to be followed.
(a) Check to see if the proposed key combo is already assigned. (This could be done via the array from Sketchup::get_shortcuts.) If so, find another combo to propose.
(b) Propose the key combo as an accelerator to the user via a Yes / No dialog.
(Yes) Assign it.
(No) Display the Shortcuts panel of the Preferences dialog. Ie, UI.show_preferences("Accelerator")

(3) Currently trying to “poke” an accelerator into the Windows registry may not work, as SketchUp likes to overwrite many of the SketchUp registry keys and attributes when it closes. (But you could try it.)
It would be safer done when all SketchUp instances are closed. Which might mean an external utility, or a temporary batch script saved to the user’s Desktop.

For Shortcuts there is no API methods to ‘set’, only to ‘get’.
You could have course hack the registry on PC [plist on MAC], BUT the reason most authors avoid this is because you could upset users if you overwrite their own custom shortcuts.

I recall that thomthom did use key presses within one of his tools [VertexTools?] to mimic native shortcuts - like M for Move - I’m not sure how he did it - I suspect he had to temporarily suspend the native shortcut key or spot if the M activated the Move tool then cancel it and go back into his own tool’s Move ? - otherwise simply pressing M within your own tool activates the native Move tool and skips out of your tool…
I suggest you ask thomthom…

I created a special function that would know when my Vertex Tools was active (the Ruby tool was active) and either activate my own Vertex Move or the native Move depending on editing mode. However the user was required to remap their shortcuts. I documented this in the manual.

However, for version 2 I’m using ToolsObserver to detect this. So if my Ruby tool is active and the user activates the native Move tool I’ll swap it out with my custom Vertex Move tool. No remapping required and only triggers when I know the user is using my tool.

I’d discourage remapping user shortcuts programatically - changed globally. As a user I’d be very unhappy if my carefully crafted shortcuts where changed.

1 Like

Agreed. And most others would also.

But what do ya’ think of (2) above ?

Do you think it’s worth logging ?

When do you think such a proposal should be presented to the user ? (During startup cycle might slow things way down.)


New SU user here, but old time hand at using CAD. One of the handiest things I did using that other CAD program was to map a couple dozen shortcuts to keys that were under my left hand while sitting on the home row of QWERTY keyboard. I used all the single key shortcuts that I could stroke easily without moving my hand. I then used double key shortcuts to commands. I would also use two-key shortcuts to commands. Using this strategy allowed me to keep one hand on mouse and one hand on keyboard and move very, very quickly thru workflow. I wasn’t constantly moving one hand or the other to a ‘modifier’ key such as ‘control’ or ‘alt’ or ‘window/cmd’ keys. Leaving my hands ‘in place’ was much more efficient for entering shortcuts. True, it took some practice and learning, but once I had the ‘muscle memory’ down, it was quick!

For instance, I would like to make the following ‘shortcuts’:

Single key A = 2 point Arc
Double key AA = 3 point Arc

Single key G = Make Group
Double key GG = Make Component
Sequence FD = Flip Along Red Axis
Sequence DF = Flip Along Green Axis

All the above are easily reached while left hand is on home row of keyboard. Another example, ‘O’ is shortcut for Orbit, but wouldn’t it be great if I could assign it to ‘FF’? At present I can’t do that. Seems SU limits ‘shortcuts’ to a single key, or one of three ‘modifier’ keys along with a key to map that shortcut to a command.

Just a thought and suggestion.

1 Like

You are correct.

You and a lot of other users who came from CAD, and still may also use CAD in their workflows.

It has been requested several times, and usually starts an argument between those for and against. (I am always on the side that lets the user use the product in their own way. Ie the “U” in GUI is “user”.)

But the more people who politic for it, the better it’s chances of climbing up the “possible feature list”. (Those that remain on the bottom will never get considered for implementation.)

So I would suggest you cut and paste your whole post above into a new thread in the Feature Requests category. It deserves it’s own thread (And may have had one in previous forum sites.)

Previously, it was buried in the middle of a “Wish List 2016” thread:

Done. Thank you for the quick response!

I came here because I was looking for a way to automatically set shortcuts from within my plugin. I know there is a way to import a shortcuts file (manually in the UI), but I was thinking it would be handy to have an option in my plugin to automatically set shortcuts.

My thought was I would show a list of shortcuts for my extension functions. Shortcut s already in use would show a warning, and the user could select which shortcuts to set. Oh well. So much for that Idea.

If you create menu items for commands, then the user can set their own shortcuts.

I do, and I can set the shortcuts in the UI, either manually, or by importing them.

I just thought it would be nice to offer the user the option to automatically set them to the preferred defaults.