| Re: howto bind shortcut key to button [message #34082] |
Wed, 19 February 2003 06:24  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Sebastian (s@visita2.die.upm.es) writes:
> is there a way to bind a shortcut key to a button?
> I would like to do something like pressing CTRL+S while my app is in
> hte foreground evokes myapp->save.
> I didn't find anything useful on this in the manual and the ng archive,
> and the idl demo doesn't seem to use keyboard short-cuts.
Under Microsoft Windows, including the ampersand character (&) in the
value of a button widget causes the window manager to place an underline
under the character following the ampersand. This is a feature of
Microsoft Windows, and is generally used to indicate which character is
used as a keyboard accelerator for the button. If you plan to run the
application on *anything* other than Windows, though, forget it.
The ampersand will show up on the button and there will be
no accelerating effect. This is a WINDOWS ONLY feature. :-(
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
|
| Re: howto bind shortcut key to button [message #34213 is a reply to message #34082] |
Thu, 20 February 2003 08:05  |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Wed, 19 Feb 2003 07:24:53 -0700, David Fanning wrote:
> Sebastian (s@visita2.die.upm.es) writes:
>
>> is there a way to bind a shortcut key to a button? I would like to do
>> something like pressing CTRL+S while my app is in hte foreground evokes
>> myapp->save.
>> I didn't find anything useful on this in the manual and the ng archive,
>> and the idl demo doesn't seem to use keyboard short-cuts.
>
> Under Microsoft Windows, including the ampersand character (&) in the
> value of a button widget causes the window manager to place an underline
> under the character following the ampersand. This is a feature of
> Microsoft Windows, and is generally used to indicate which character is
> used as a keyboard accelerator for the button. If you plan to run the
> application on *anything* other than Windows, though, forget it. The
> ampersand will show up on the button and there will be no accelerating
> effect. This is a WINDOWS ONLY feature. :-(
>
Two other options:
1. My old hidden WIDGET_TEXT hack (see
http://dfanning.com/widget_tips/keyboard_events.html). May work
with modifier keys and arrow keys (if you use an even wierder hack
-- search the NG for "key events"). Not terribly platform
independent.
2. A hidden WIDGET_DRAW (or actual widget_draw if your application
uses it) with KEYBOARD_EVENTS set. Only available starting with
IDL v5.6. Works well with modifier keys and arrow/PageUp|Down
keys. Should be platform independent.
The problem with both of these solutions: you need to give the
appropriate widget text focus. With #2, it will occur automatically
when you interact with the draw widget. I personally would have liked
KEYBOARD_EVENTS to be WIDGET_BASE, which would be delivered events if
no other element had text focus. The workaround I use: set
TRACKING_EVENTS on the top-level widget base, and explicitly give the
appropriate widget focus when entering the application.
Good luck,
JD
|
|
|
|