Re: How to determine whether the ALT-key is pressed
Hi Dave,
I've just made another test, and the result confuses me.
The original code from VC++21day is as follows:
void CMausDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
char lsChar;
HCURSOR lhCursor;
lsChar = char(nChar);
if (lsChar == 'A')
lhCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
else if (lsChar == 'B')
lhCursor = AfxGetApp()->LoadStandardCursor(IDC_IBEAM);
else if (lsChar == 'C')
lhCursor = AfxGetApp()->LoadStandardCursor(IDC_WAIT);
else if (lsChar == 'X') {
lhCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
SetCursor(lhCursor);
OnOK();
}
m_bCursor = TRUE;
SetCursor(lhCursor);
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
This works just fine. Now I want to see what the charcode is if ALT is
pressed together with, e.g. 'A'. So I modified the code as follows:
........................................
lsChar = char(nChar);
CString s;
s.Format("%d", lsChar);
MessageBox(s);
if (lsChar == 'A')
........................................
I expected that the Messagebox will show me the charcode. But to my surprise
I got nothing if I pressed ALT+A. Obviously the keydown event is no more
invoked if ALT is pressed together with another key.
--
Weichao Wang
"David Lowndes" wrote:
in "VC++ in 21 Days" I found the following:
...
Yes, that's just reiterating the documentation - which may be
literally correct, but not strictly applicable in your situation.
1. When you debug the key down event for the Alt key, do you hit your
OnKeyDown handler?
2. If you do, show us the code you've written.
3. If you don't, use Spy++ - you'll probably find you're getting a
WM_SYSKEYDOWN message rather than WM_KEYDOWN.
Dave