handling keyboard input in the message handler

Started by
12 comments, last by Merc22 23 years, 1 month ago
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
Advertisement
WM_CHAR

Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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;
And the coordinates of the mouse click when the message is sent is stored in the the LOWORD(lParam) and HIWORD(lParam) which are the X,Y coordinates.
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
}

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.
ic

then how would i check to see what letter is being pressed?

sorry to be annoying u with these questions
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?
i cant get my Dev C++ to wotk with Directx

im tryin to make a simple game without directx or anything just win32
That would be kinda hard duncha think?

But anyway,

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

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

This topic is closed to new replies.

Advertisement