Mnemonic and Accelerator Issue

  • Thread starter Thread starter msoegrad
  • Start date Start date
M

msoegrad

In doing some development and testing I have found a curious issue with
the use of Mnemonics and Accelerators that I would like some input on.
If you create a form that has 2 buttons on it, one with text "&Button1"
and one with "B&utton2" and set up event handlers for both you will see
a curious reaction with the accelerators. If nothing has focus the
Alt+key combination works fine. If one has focus it still works fine
but you can just press the key for the other button and that event will
still fire. IE if button one has focus and your press "u" Button2 will
fire as if you had pressed Alt-U. The application I am working on has
a list of options the user can select from that have hotkeys associated
with them that are 0-9 and A-H. At the bottom of the screen is a
button that is supposed to respond to the Alt-A keypress where the
others are just the single keypresses (no Alt-combos). However if you
press A, you not only go to the appropriate screen, but the dialog from
the button also opens up. Has anyone seen this before or know of a way
to correct this issue besides changing the Accelerator for the button.
 
In doing some development and testing I have found a curious issue with
the use of Mnemonics and Accelerators that I would like some input on.
If you create a form that has 2 buttons on it, one with text "&Button1"
and one with "B&utton2" and set up event handlers for both you will see
a curious reaction with the accelerators. If nothing has focus the
Alt+key combination works fine. If one has focus it still works fine
but you can just press the key for the other button and that event will
still fire.

OK, that is the (current) expected behaviour. I think that early
versions of Windows only worked with the Alt+key combination, and I
can't recall when the single key accelerator behaviour came in. Of
course if focus is on a control that normally accepts keys (such as an
edit field), the single key accelerator won't work.
application I am working on has
a list of options the user can select from that have hotkeys associated
with them that are 0-9 and A-H.

What mechanism are you using for these hotkeys?

Dave
 
We are just catching in the ProcessCmdKeys and for each key we iterate
through our control collection and check against the ShortcutKey
property of each of the child controls on the form that implement our
interface..
 
We are just catching in the ProcessCmdKeys and for each key we iterate
through our control collection and check against the ShortcutKey
property of each of the child controls on the form that implement our
interface..

Ah, this sounds like a .Net WinForm application?

Anyone have any suggestions?

Presumably you need to prevent the keystoke being default processed
after you've determined it's one of your shortcut keys, but I don't
know how you'd do that.

Dave
 
I'm having a problem along the same lines. But I believe the problem is more
fundamental and pervasive. To reproduce, simply do this:
1. create a new C# "Windows Application" project (I'm using VS2005)
2. Add a button to the form and change its default Text from "button1" to
"&button1"

Now run the app. Press the alt key on the keyboard and the keyboard cue is
displayed (the 'b' becomes underlined). Press the alt key again and the
underline does not go away. You will also notice that pressing the 'b' key
fires the button's click event regardless of whether the alt key was ever
pressed, or whether the cue is visible.

Surely this isn't "by design" (menus don't work this way!)

Any pertinent suggestions on how to work around this would be welcome. TIA
 
Back
Top