Re: Detecting Ctrl from OnKeyDown?
"sg" <sg@sg.com> wrote in message
news:%23$$PrCK4JHA.1380@TK2MSFTNGP05.phx.gbl...
davep15@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?
GetAsyncKeyState(VK_CONTROL)
If I remember right that tells you the state at the moment you call the
function, and GetKeyState() tells you the situation when the last keyboard
message arrived.
I wrote a utility function years ago and have never had to worry about it
since:
//===
// In a universally available header file:
//===
const UINT KBD_NONE = 0x00000000;
const UINT KBD_ALT = 0x00000004;
const UINT KBD_CTRL = 0x00000002;
const UINT KBD_SHIFT = 0x00000001;
const UINT KBD_CTRLSHIFT = (KBD_CTRL|KBD_SHIFT);
const UINT KBD_ALTCTRL = (KBD_ALT|KBD_CTRL);
const UINT KBD_ALTSHIFT = (KBD_ALT|KBD_SHIFT);
const UINT KBD_ALTCTRLSHIFT = (KBD_ALT|KBD_CTRL|KBD_SHIFT);
//===
// In my utilities library:
//===
UINT KeybdAltCtrlShift()
{
UINT uResult = 0;
if( GetKeyState( VK_MENU ) & 0x8000 ) uResult |= KBD_ALT;
if( GetKeyState( VK_CONTROL ) & 0x8000 ) uResult |= KBD_CTRL;
if( GetKeyState( VK_SHIFT ) & 0x8000 ) uResult |= KBD_SHIFT;
return uResult;
}
I use it in all sorts of places within responses to WM_CHAR and WM_KEYDOWN
and WM_SYSKEYDOWN.
Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm