Not that difficult, I think it's about 6 lines of code total. You just have
to call TranslateAccelerators in PreTranslateMessage. (Maybe 5 minutes worth
P.S. I didn't see anything in the original post about the type of
I think OP was doing a dialog application. That makes using an accelerator
key setup a little more difficult.
"Malachy Moses" <email@example.com> wrote in message
On May 29, 11:35 am, dave...@gmail.com wrote:
I'm attempting to add some global hot keys to my application (Like Ctrl
+O to open, or Ctrl+P to print) I looked at the OnKeyDown method but
it appears to only tell me if Alt was pressed with the key, not Ctrl.
Is the OnKeyDown the right way to do this?
If so how do I get the Ctrl key info?
Global hot keys should be added using an accelerator table. Use of
OnKeyDown (or OnChar or whatever) is an abomination. In the words of
"Many programmers attempt to use OnChar. No, no, no! OnChar is a low-
level mungy-grungy sort of thing you want to avoid any time you can.
Even worse are WM_KEYDOWN, WM_ KEYUP, and the like. Who can deal with
that stuff? OnChar is OK if you want to restrict the characters
allowed in an edit control to, say, numeric digits, but any time you
want to map a key to a command, accelerators are the way to go."
In addition, PreTranslateMessage should not be needed.
PreTranslateMessage would be needed only if you have a dialog-based
application and you need to override PreTranslateMessage in order to
add a call to ::TranslateAccelerator(). An MFC app with a CFrameWnd
already has this code; thus nothing more is needed beyond an entry in
the accelerator table if your app is not dialog-based. This is
explained at the DeLascia article cited above.