7 Replies Latest reply on May 16, 2018 8:28 AM by Taus Moller

    Keyboard Shortcuts and s-key flyout for third party add-ins

    Taus Moller

      We would like to provide some shortcuts for our third party add-in. However, i am having a hard to time figuring out how to do this. For now i would just like to be able to add some keyboard shortcuts for the stuff we have in the command manager and context menus. At the very least we would like the user to be able to assign their own shortcuts through the Solidworks customization dialog.

       

      If i go to Tool->customize I see our add-in represented in the "Toolbars" tab and the "Commands" tab, allowing the user to add a toolbar and customize where to show our buttons. However, in the "Keyboard" and "Shortcut Bars" tab where a user would be able to set keyboard shortcuts or add it to their s-key flyout it is nowhere to be found.

       

      Do we need to register our methods additional places to make them available for keybinding and s-key flyout?

       

      EDIT:

      Jason and Amen got me most of the way with this. I added a post with some additionally information on how to setup default shortcuts

        • Re: Keyboard Shortcuts and s-key flyout for third party add-ins
          Amen Allah Jlili

          Set a keyboard shortcut for any of your add-ins command then export SOLIDWORKS settings. When you edit the output file, you'll be able to see what registry key were associated with your command.

          • Re: Keyboard Shortcuts and s-key flyout for third party add-ins
            jason van clark

            We have this problem too with our in-house tools.  To get your add-in buttons on the shortcut bars:

            Tools>customize>Toolbars

            Copy your buttons to an already visible toolbar (i use the menu bar myself)

            Switch to tools>customize>shortcut tab

            drag your buttons onto the shortcut

            Press ok

            (side note: this works for other add-ins too, like workgroup pdm icons)

             

            As for keyboard shortcuts, your commands should be in the list of commands somewhere.  Have you tried searching for them?

            • Re: Keyboard Shortcuts and s-key flyout for third party add-ins
              Taus Moller

              Just writing a follow with some answers to the rest of the question.

               

              Shortcuts:

              First things. To add a keyboard shortcut you have to add menu items for the features you want keyboard shortcuts for. It is not enough for them to be in a toolbar or the command manager. This is done with SwAddin.AddMenuItem5 . After doing that you will see your menu items available in the Tool->Costumize->Keyboard shortcuts. Here you can bind shortcuts to you menu items.

               

              Default Shortcuts

              If you want to provide default shortcuts to you menu items, this is done through editing the Registry. To see how this looks you can bind a shortcut to one or more of you menu items and go to Tools->Save/Restore Settings. This gives you a registry file showing the structure. It was not immediately apparent to me what the system was, so i will just give short summary. They apparently use this structure: Accel

               

              When exporting your setting it will come out looking something like this:

               

              [HKEY_CURRENT_USER\Software\SolidWorks\SOLIDWORKS 2017\Customization\tPlate0\Custom Accelerators\AddArray\31_65]
              "fVirt"=dword:0000001f
              "key"=dword:00000041
              "cmd"=dword:00008673
              

               

              For unknown reason it actually outputs this three time with "tPlate0" tPlate1" and "tPlate2" for me.

               

              Apart from that, there are 4 variables hidden in this registry entry. As well as an additional thing to be aware of

               

              The variables are

              1. The first is simple enough. It is your solidworks version.

              2 "fVirt" is flags for modifier keys for the short cut. I.e. ctrl, shift and alt. The flag values can be seen in the Accel link above. Just know to always in include 0x1 and 0x2

              In the example it is 0x1f which is all three keys. 0x1 + 0x2 +0x4 (Shift) + 0x8(CTRL) +0x10(ALT) = 1f

              3. "key" is a virtual keycode In the example above 0x41 is the "a" key.

              4. "cmd" is the command id assigned by solidworks. You can get this in two way. Bind keys and export or use the return value of AddMenuItem5. Remeber to convert to hex though. In the example above AddMenuItem returned 34419 which is equal to 0x8673. I am bit unsure however if this is consistent across version and system, so you should probably to some testing with this

               

              The last thing to be aware of is where it says "31_65" these number are "fVirt" and "key" in decimal. I.e. fVirt = 0x1f = 31 and key = 0x41 = 65. if i instead wanted to bind to ctrl+B , i would set fVirt = 0x1 + 0x2 + 0x4 = 0x7 and key = 0x42 and create the key

               

              [HKEY_CURRENT_USER\Software\SolidWorks\SOLIDWORKS 2017\Customization\tPlate0\Custom Accelerators\AddArray\7_66]

               

              I hope this helps.