3

I would like to have some shortcuts with alt but when I press alt the menustrip gets selected. How can I disable this behaviour?

H H
  • 263,252
  • 30
  • 330
  • 514
DaVinci
  • 1,391
  • 2
  • 12
  • 27
  • 3
    Why do you want to make your application less usable? – Oded Dec 27 '10 at 09:46
  • I want to make it more usable, with shortcuts but there are only X keys on my keyboard. Try to argue with a vim or emacs user that there editor is less usable just because it doesn't use the native combinations. – DaVinci Dec 27 '10 at 09:51
  • this will make it less usable. Are you aware that you can use control, alt and shift modifiers in combination? – David Heffernan Dec 27 '10 at 10:02
  • 1
    The ALT key allows the user to access *every* item on the MenuStrip, regardless of whether or not it has a specific shortcut key assigned. Honestly, you need not assign shortcut keys to *every* function, only the most commonly used ones. You *can* combine ALT with CTRL when creating shortcuts, but you should not use it alone. When you find that you have run out of shortcut keys using combinations of CTRL, SHIFT, ALT, and the F-keys, you probably have enough. – Cody Gray - on strike Dec 27 '10 at 10:04
  • Slow down a minute and think this through. After you have disabled keyboard access to the menu, think about how your app's users are going to access the menu by the keyboard. @Cody Gray is bang on the money as usual - too many shortcuts will dilute the value of having shortcuts for the most important actions. – David Heffernan Dec 27 '10 at 10:09

2 Answers2

2

This is why, on Windows, you do not use ALT+key shortcuts. You should not attempt to subvert the native system behaviour. The solution is to choose a different shortcut combination.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0

I know this thread is old, but I am running into the same problem.

One partial solution is to use the "SendKeys.Send" function to simulate a second press of the alt key. For example, to simulate the user pressing "alt-0":

sendkeys.send("%0")

This works because pressing the Alt-key once activates the menu strip, but pressing it a second time deactivates it.

The only problem is, this also tricks the software into thinking that the user let go of the Alt- key. So it doesn't work if you want to be able to press and hold the Alt-key while pressing some other keys.

Since the Alt-key triggers the menustrip.activate event, it seems there should be someway to trigger the menustrip.deactivate event in code without the hack of simulating another Alt-key press, but I can't figure out how to do that...