|
From: JVZ <je...@fo...> - 2017-01-12 01:58:30
|
On Wed, 11 Jan 2017 14:25:20 -0500
"Julia Dudascik (Contractor)" <jul...@un...> wrote:
>Hi,
>
>I would like to add a HotKey in my Main Window. When the user presses the
>button Ctl+Q (Control Q), I would like the application to exit. In the
>constructor where I create my window, I did the following:
>
>FXHotKey test = parseHotKey("Ctl-Q")
>this->addHotKey(test)
>this->accelTable->addAccel(test, this, ID_TEST_HOTKEY)
>
>Then in FXMAPFUNC, I define:
>FXMAPFUNC(SeL_KEYPRESS, MyClass::ID_TEST_HOTKEY, MyClass::test_hot_keyFunc),
>
>When I pres Control Q, the application never gets to my function
>test_hot_keyFunc.
>
>Did I define the hotkey correctly for Control q?
>How do you set-up a hot key for a window, so that the user can quit the
>application
>with the command Ctl-Q in the main window?
>
>This is just one instance on shortcuts I would like my "Main Window" to
>have. For instance, I would also like to save the database with the command
>Ctl+S. I am first trying to figure out how to add a hot key to a window
>before proceeding, Any assistance would be greatly appreciated.
>
>Thank you
>Julia
You should want to use parseAccell() instead of parseHotKey(). parseAccel()
is for strings like "Ctl-Q" and "Shift-Alt-F3". The parseHotKey()( is for
strings that are part of a menu or label, such as "&Open File" (which
would add a hotkey Alt-O, active only when the label or menu is presented.
Now, since you're supplying the text directly, you might as well just skip
the step and call acceltable->addAccel() directly, like:
getAccelTable()->addAccel(MKUINT(KEY_Q,CONTROLMASK),mytarget,FXSEL(SEL_COMMAND,MyWidget::ID_THEMESSAGE));
This would be a lot simpler.
Of course, if your program has pulldown menus, you can make your life even easier
by just passing a special string to the Quit option:
menubar=new FXMenuBar(...);
filemenu=new FXMenuPane(...);
new FXMenuTitle(menubar,"&File",NULL,filemenu);
new FXMenuCommand(filemenu,"&Open...",...);
...
...
...
new FXMenuCommand(filemenu,"&Quit\tCtl-Q",...);
In FXMenuTitle, the string "&File" would automatically add a hot-key Alt-F to
bring up the menu, while the string "&Quit\tCtl-Q" would not only add a hot-key
Alt-Q but also an accelerator Ctl-Q.
Since most applications would have a menubar, this is by-far the easiest way to
add hotkeys and accelerators.
But every once in a while, you may have an accelerator that does not have a corresponding
menu, or maybe have an app that has no menus; in such a case, directly adding the key-combo
to the accelerator table may be the way to go....
Hope this helps,
-- JVZ
|