Archived

This topic is now archived and is closed to further replies.

handling keyboard input in the message handler

This topic is 6114 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im really confused with this problem the problem is how do i check for keyboard input in the message handler? like what are the scan codes and such? one other thing does anyone knoe a good way of checkin where the mouse is clicking?(example- how to check if the mouse clicks in a box?) thanx

Share this post


Link to post
Share on other sites
In Win32 or DirectInput?

I will assume you''re using Win32.

When a key is pressed, a WM_CHAR message is sent.
It''s character is stored in wParam.

Also, a WM_KEYDOWN is sent.
The characters stored in wParam are raw, ie they have no other properties. Eg is the user press Ctrl while pressing e, it will not be E but just e.

case WM_KEYDOWN:
switch((char)wParam)
{
case VK_UP:
break;
}

WM_KEYUP works the same way.

Mouse messages are:
WM_LBUTTONDOWN
WM_RBUTTONDOWN
WM_LBUTTONUP
WM_RBUTTONUP
WM_LBUTTONDBLCLK
WM_RBUTTONDBLCLK

When you need to test for Double-clicks:
wcl.style = CS_DBLCKS;

Share this post


Link to post
Share on other sites
thanx Darkor

but i didnt get this part:

case WM_KEYDOWN:
switch((char)wParam)
{
case VK_UP:
break;
}

y is WM_KEYDOWN being used the VK_UP is also used?

can i do this with wParam:

switch(wParam)
{
case ''n'':
break;
case ''s'':
break;
etc
}

Share this post


Link to post
Share on other sites
case WM_KEYDOWN:
switch((char)wParam)
{
case VK_UP:
//Up key is being pressed
break;

case VK_SPACE:
//space key is being pressed
break;

}

These are VK_ codes and are not the messages.

I dont think so, you''d have to cast it.

Because wParam is of type WPARAM.

Share this post


Link to post
Share on other sites
No I dond''t mind your questions.

I ran into that trouble a few months back and...
I havn''t found a solution except to use DirectInput.

Maybe you could use WM_CHAR.

The VK codes only support the keys other than characters, I don''t know why.

Using DirectInput is actually easier, are you creating a game or just a Win32 app?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Darkor

case WM_CHAR:
switch((char)wParam)
{
case ''c'':
break;
}

This would definitely work but it won''t test for enter keys and the like.


That will work for enter keys and the like, you just need to know the ascii character code for them.

Share this post


Link to post
Share on other sites