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
AliR.
P.S. I didn't see anything in the original post about the type of
application.
I think OP was doing a dialog application. That makes using an accelerator
key setup a little more difficult.
Tom
"Malachy Moses" <malachy.moses@gmail.com> wrote in message
news:988a9b14-b09f-453c-8310-9d320aaaf32d@l32g2000vba.googlegroups.com...
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
Paul DeLascia:
"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."
See http://msdn.microsoft.com/en-us/magazine/cc301409.aspx
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.