Personal Keyboard Shortcut List Extension or Ruby Method

Dear All,

There have been several posts regarding printing a list of shortcuts for SketchUp, but the solutions offered largely relate to default shortcuts. Is there a way (for example extension or ruby method) that will allow a person to print all shortcuts (default and user added)? Even better would be a table having a column of commands that can be assigned a shortcut and a second column with currently assigned shortcuts (or null if no shortcut).

I know I should know my own shortcuts, but I don’t always know them when I need them.

Thank you for your kindness, understanding, and help.

Best Regards,

Tom

The Sketchup #get_shortcuts method retrieves an array of all keyboard shortcuts currently registered with SketchUp

shortcuts = Sketchup.get_shortcuts

get_shortcuts

2 Likes

Dezmo,

That is absolutely great! Thank you so much. A little Regex and I am almost there!

Any chance there is a similar query that will show all commands that can have shortcuts?

Thank you very much for your help.

Regards,

Tom

1 Like

Another way to skin the cat, from the Sketchucation Extension:

image

1 Like

Thanks. What is sort of odd is that, on MacOS, the cmd key shortcuts are not listed using the get_shortcuts method. For example, cmd-g invokes the ‘make group’ command and shift-cmd-g invokes ‘make component’ command.

The cmd shortcuts that you see in the menu’s are MacOS specific and can’t be altered or changed.

on windows machines there is a file called preferences.dat that is created and stores file locations and shortcuts. It can be opened and edited with a text editor like Notepad++. Not sure if it does the same on a MAC.

A couple of versions ago (don’t remember off-hand which) SketchUp changed where shortcuts are stored to put them in the SharedPreferences.json file on both Windows and Mac. preferences.dat is no longer used.

However, this does not change the fact that on both platforms standard shortcuts into the menu system are coded and compiled into the app and not shown by the Ruby get_shortcuts method. Further, as @MikeWayzovski pointed out, on Mac a user cannot set a persistent Cmd- shortcut. It used to be that you would get a warning. At least in 2023, it simply is ignored when you try to enter it in the settings panel.

1 Like

You can display in a multiline messagebox:

shortcuts = Sketchup.get_shortcuts.sort.map { |txt| txt.split("\t") }
pattern = "%-12s : %s\n"
shortcuts.map! { |ary| format(pattern, *ary) }
UI.messagebox(shortcuts.join, MB_MULTILINE)

But they do not yet use monospace text.
It is much nicer to display in a HTML dialog.

Basic Example (... click to expand ...)
module Help
  def self.list_shortcuts
    @shortcuts = UI::HtmlDialog.new(
      dialog_title: 'Shortcuts Listing',
      preferences_key: 'Help_Shortcuts_Listing'
    )
    shortcuts = Sketchup.get_shortcuts.sort.map { |txt| txt.split("\t") }
    pattern = "<tr><td>%s</td><td>%s</td></tr>"
    shortcuts.map! { |ary| format(pattern, *ary) }
    @shortcuts.set_html(%[
      <!DOCTYPE html>
      <html>
        <head>
          <style>
            html { 
              font-family: Consolas, monospace;
              font-size: 0.8em;
              padding: 0.3rem;
              margin: 0;
            }
            table {
              border: solid black 0.2rem;
              border-collapse: collapse;
              padding: 0;
            }
            thead {
              border-bottom: solid black 0.2rem;
            }
            tr {
              border-width: 0.1rem;
              border-style: solid none;
            }
            td {
              padding: 0.3rem 0.8rem 0.3rem 0.3rem; 
              border-width: 0.1rem;
              border-style: none solid;
            }
          </style>
        </head>
        <body>
          <table>
            <thead>
              <tr><td><b>Shortcut Key(s)</b></td><td><b>Command</b></td></tr>
            </thead>
            <tbody>
              #{shortcuts.join("\n")}
            <tbody>
          </table>
        <body>
      </html>
    ])
    @shortcuts.show
  end

  unless defined?(@loaded)
    UI.menu('Help').add_item('&List Shortcuts',0) { self.list_shortcuts }
    @loaded = true
  end
end # module
1 Like