Community
Showing results for 
Search instead for 
Do you mean 
Reply

shortcut keys

Nickel Elite Contributor
Posts: 508
Country: USA

shortcut keys

I'd like to add a shortcut key to a menu item I added (which runs a plugin) - e.g. Ctrl + G

 

How would that be done.  Thanks...

Richard Brust
ACT! Certified Consultant
richard@rbrDataSolutions.com
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: shortcut keys

Something like this should work:

 

' Set the shortcut to "ALT+F11"

 

ACTAPP.Explorer.CommandBarCollection("Connected Menus").ControlCollection(ACTUrn).ShortcutKeys = New Keys() {CType(System.Windows.Forms.Keys.Alt, System.Windows.Forms.Keys), CType(System.Windows.Forms.Keys.F11, System.Windows.Forms.Keys)}

 

 

-- Jim Durkin

Nickel Elite Contributor
Posts: 508
Country: USA

Re: shortcut keys

Thanks for your help.  I've been working with variations of that, but haven't seemed to iron it out.  Not only does the shortcut not work, the plugin does not load with these lines in.

 

Public Sub AddMenuItem(ByVal urn As String, ByVal MenuText As String, ByVal Handler As Act.UI.CommandHandler)

 

 'Dim SK() As System.Windows.Forms.Keys = {Keys.G, Keys.Control}

  If (MenuItemExists(urn) = True) Then

    RemoveMenuItem(urn)

  End If

 

  Dim ParentMenu As Act.UI.Core.CommandBarControl

  ParentMenu = CType(ActApp.Explorer.CommandBarCollection("Connected Menus").ControlCollection(GetParentControlURN(urn)), _

    Act.UI.Core.CommandBarControl)

  'ParentMenu.ShortcutKeys = _

  '  New Keys() {CType(System.Windows.Forms.Keys.Alt, System.Windows.Forms.Keys), _

  '              CType(System.Windows.Forms.Keys.F11, System.Windows.Forms.Keys)}

 

  Dim NewMenu As Act.UI.Core.CommandBarButton

  NewMenu = New Act.UI.Core.CommandBarButton(MenuText, MenuText, Nothing, urn, Nothing, Nothing)

  NewMenu.DisplayStyle = Act.UI.Core.CommandBarControl.ItemDisplayStyle.TextOnly

  'NewMenu.ShortcutKeys = SK

 

  'ActApp.Explorer.CommandBarCollection("Connected Menus").ControlCollection(urn).ShortcutKeys = SK

 

  'ActApp.Explorer.CommandBarCollection("Connected Menus").ControlCollection(urn).ShortcutKeys = _

  '  New Keys() {CType(System.Windows.Forms.Keys.Alt, System.Windows.Forms.Keys), _

  '              CType(System.Windows.Forms.Keys.F11, System.Windows.Forms.Keys)}

 

  ActApp.RegisterCommand(urn, Handler, Act.UI.RegisterType.Shell)

  '*** adds Menu Item, remove to just add icon ***'

  ParentMenu.AddSubItem(NewMenu)

End Sub

 

You can see all the places I've tried it, and diff variations, just no luck...

Richard Brust
ACT! Certified Consultant
richard@rbrDataSolutions.com
Bronze Super Contributor
Posts: 1,231
Country: USA

Re: shortcut keys

Richard,

Wrap it in a try/catch to debug the error.

 

 Public Sub AddMenuItem(ByVal urn As String, ByVal MenuText As String, ByVal Handler As Act.UI.CommandHandler)

        Try

        '-------------------------

        ' Your code here

        '-------------------------

         Catch ex As Exception

                System.Windows.Forms.MessageBox.Show(ex.Message)

                System.Diagnostics.Debugger.Break()

        End Try

End Sub

 

-- Jim Durkin

Nickel Elite Contributor
Posts: 508
Country: USA

Re: shortcut keys

Thanks, that gave me a "Object reference not set to an instance of an object", which made me think to move the line down after the menu was added:

 

  ActApp.RegisterCommand(urn, Handler, Act.UI.RegisterType.Shell)

  '*** adds Menu Item, remove to just add icon ***'

  ParentMenu.AddSubItem(NewMenu)

  ActApp.Explorer.CommandBarCollection(
"Connected Menus").ControlCollection(urn).ShortcutKeys = _

    New Keys() {CType(System.Windows.Forms.Keys.Control, System.Windows.Forms.Keys), _

                CType(System.Windows.Forms.Keys.G, System.Windows.Forms.Keys)}

End Sub

 

which worked - thanks again...

Richard Brust
ACT! Certified Consultant
richard@rbrDataSolutions.com
Copper Contributor
Posts: 61
Country: United_Kingdom

Re: shortcut keys

[ Edited ]

Could someone please show me what this might look like in C#

 

I've had a few attempts but none seem to work.

 

public void AddMenuItem(string aURN, string aMenuText, Act.UI.CommandHandler aHandler, CommandBarControl.ItemDisplayStyle aItemDisplayStyle, Image aImage, Keys[] aKeys)
        {
            try
            {
                if (MenuItemExists(aURN) == true)
                {
                    RemoveMenuItem(aURN);
                }

                Act.UI.Core.CommandBarControl parentMenu = oApp.Explorer.CommandBarCollection["Connected Menus"].ControlCollection[GetParentControlURN(aURN)];
                Act.UI.Core.CommandBarButton newMenu = new Act.UI.Core.CommandBarButton(aMenuText, aMenuText, null, aURN, aImage, aImage);
                newMenu.DisplayStyle = aItemDisplayStyle;
                oApp.RegisterCommand(aURN, new Act.UI.CommandHandler(aHandler), Act.UI.RegisterType.Shell);
                parentMenu.AddSubItem(newMenu, 1);

                oApp.Explorer.CommandBarCollection["Connected Menus"].ControlCollection[aURN].ShortcutKeys = aKeys;
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

 

Thanks,

 

SS

Copper Contributor
Posts: 61
Country: United_Kingdom

Re: shortcut keys

Can anyone help here?

 

Thanks,

 

 

SS

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: shortcut keys

You can convert the example above to c# using this web site:

 

 

http://www.developerfusion.com/tools/convert/vb-to-csharp/

 

Hope this helps

-- Jim Durkin