• Status: Solved
• Priority: Medium
• Security: Public
• Views: 259
• Last Modified:

# F3 + LMB

Hi,

when I used MOTIF three years ago, it was very easy to define a func. for F3+LMB message. Anybody know how to write the callback func. in MFC 5.0.

Thanks in advance,

Robin
0
st2599
Asked:
• 2
• 2
• 2
1 Solution

Commented:
Hi!
You must add message nahdler for LMB press and inside this handler you must ask state of the F3 key.
for example:
CMyWnd::OnLButtonDow(CPoint pt, UINT uFlags)
{
if (::GetKeyState(VK_F3) < 0) //<- key pressed
{
//... do something
}
}
0

Commented:
How about checking GetKeyState(VK_F3) == -128 in your OnLButtonUp(UINT nFlags, CPoint point) callback?

sunj

0

Author Commented:

sunj's answer is correct. But I am a little confusing why GetKeyState(VK_F3) == -128. I looked up the manual that if key is down, the higher order bit of GetKeyState() is 1. that means GetKeyState() will return 10000000 00000000(in bits) since the return value is a short. then it should be 2^15=32768. Why, Sunj?

About migel's comment, you may try. We will never be able to get a negative value ::GetKeyState(VK_F3) < 0) //<- key pressed
like you used.

Thanks, guys.

Robin
0

Commented:
Hi,

I think migel's comment is correct and is actually better than my answer. (Strictly speaking, my answer is not correct). According to the manual, the higher order bit of GetKeyState() is 1 when the key is down, this means exactly that the return value is a negative number. It does not have to be -128, although most of the case it is.
By the way, 10000000 00000000 is not 2^15 because the first bit '1' is treated as the sign bit.
Instead of checking GetKeyState() == -128, I think you should do GetKeyState() < 0.

sunj
0

Author Commented:
Hi,

I theory, I agree that  GetKeyState() < 0. since the high order bit of 10000000 00000000 indicates the sign. But in my program, I pressed F3 and click LMB, when prog. comes to

short t1, t2;
t1 = :: GetKeyState(VK_F3);
t2 = :: GetKeyState(VK_F2);

In the watch window, t1 = -128 and t2=1. You may try yourself. I don't why. It seems that MFC does not recognize the first sign bit.

Tao
0

Commented:
GetKeyState is not MFC function it is Windows API !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Featured Post

• 2
• 2
• 2
Tackle projects and never again get stuck behind a technical roadblock.