tags:

views:

107

answers:

1

I have 6 Buttons, labeled "_0" through "_5". I would like for each button to be pressed when the user presses the corresponding number key. Right now, they must press Alt + the corresponding number key.

I can sort of work around this by giving each button an Accelerator, but it's not quite the same thing. With accelerators, as soon as the key is pressed, the button's Clicked signal is triggered. With mnemonics, the button becomes depressed when the key is pressed, and the Clicked signal isn't triggered until the button is released. I prefer this, because it helps the user to see what is happening.

Is there any way I can get the behavior of Mnemonics, but without requiring the Alt key?

+1  A: 

You can have the gtk window catch key events with the event mask settings in the window class. I can't be much more specific than that with callbacks and key types, because I use GTKmm (C++ bindings) but the approach should be similar. Basically when you catch the required key event in your window you can call the button press in code. The window has be to selected (in focus) however.

Chris H
Thanks. Any idea what method of `Button` to use? `Press ()` doesn't seem to do anything. `Click ()` works, but it behaves the same as when I added the accelerators. If you know how to do it in GTKmm, I can probably figure out the GTK# version.
Matthew
See the gtkmm documentation for the Gtk::Widget class. There is a function call set_state. Pass it GTK::STATE_ACTIVE on button press and STATE_NORMAL or STATE_SELECTED on release.
Chris H
That works. This is messy, but it's better than nothing.
Matthew