0

I developed multiple ArcGIS Commands added in a toolbar. I want to invoke these custom commands based on the keyboard keys pressed by the user.

How to implement this?

  • Did you see this StackExchange thread? – kenbuja Mar 19 '18 at 15:26
  • Thanks kenbuja, I think there the keyboard events are wired to the windows form events. In my scenario I didn't(I couldn't find such) have such default Events for the toolbar. But I found the similar solution for my scenario in gis.stackexchange.com/questions/59098/… – Venkat Mar 20 '18 at 9:06
4

You could try the following:

  1. Click the "Customize" Menu Option (Between Geoprocessing and Windows)
  2. Then Customize Mode
  3. Select the "Commands" Tab
  4. At the bottom of this form on the left is a button called Keyboard... Click it
  5. Find your tool, and then select the "New Shortcut Key" you want, and then the "Assign" button
  6. Then close the window

Please note I think this will only work on the machine that has had this done. As in if you save the MXD I am not sure the shortcut will carry over to a new user of that MXD.

It will need to be tested.

  • Thanks Keagan, but I am trying to use an interface in my code to assign same shortcuts for commands in every user machine. The changes done as above will be saved in Normal.mxt and only available to the current user in that machine. – Venkat Mar 19 '18 at 8:54
  • Ah ok...I am sorry I am not sure how that is accomplished. – Keagan Allan Mar 19 '18 at 9:45
2

I achieved this by using a separate class using KeyPressEventHandler similar to as suggested in How to use shortcuts in dockable windows?

and initialized it in my toolbar class where all the custom commands are added to toolbar as below:

KeyboardHook _KeyBoardHook = new KeyboardHook();

_KeyBoardHook.OnKeyPressEvent += new KeyPressEventHandler(KeyBordHook_OnKeyPressEvent);

KeyBordHook_OnKeyPressEvent is the method where I define the shortcut for a command as below:

if (e.KeyChar == 'a' || e.KeyChar == 'A')
{
 UID uid = new UIDClass();
 uid.Value = "MyProject.MyCustomCommand";
 uid.SubType = 3;
 ICommandItem item = 
 _application().Document.CommandBars.Find(uid, false);
 item.Execute();
}               

item.Execute calls the command OnClick() method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.