is this a good way to do this?
Code:case WM_KEYDOWN:
{
int KEY_LEFT = GetKeyState(VK_LEFT);
if(LOWORD(KEY_LEFT))
{
MessageBox(hWnd, "Pressed", "Pressed", MB_OK);
}
}
Printable View
is this a good way to do this?
Code:case WM_KEYDOWN:
{
int KEY_LEFT = GetKeyState(VK_LEFT);
if(LOWORD(KEY_LEFT))
{
MessageBox(hWnd, "Pressed", "Pressed", MB_OK);
}
}
I don't know. Did it work :confused:
try this:
Code:bool bKeys[256];
....
case WM_KEYDOWN:
{ bKeys[wParam] = true;
return(0);
}
case WM_KEYUP:
{ bKeys[wParam] = false;
return(0);
}
....
Well, here is what I have which works GOOD except 1 thing. If you are holding down a direction, then hold down another (to go diagonal for example), there is a slight pause before you start to go in the diagonal direction.
Code:case WM_KEYDOWN:
{
RECT rcClient;
HDC hDC = GetDC(hWnd);
GetClientRect(hWnd, &rcClient);
switch((int)wParam)
{
case VK_LEFT:
KEY[LEFT] = 1;
break;
case VK_RIGHT:
KEY[RIGHT] = 1;
break;
case VK_UP:
KEY[UP] = 1;
break;
case VK_DOWN:
KEY[DOWN] = 1;
break;
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
UpdateShip(&rcClient, KEY);
DrawShip(hDC, &rcClient);
}
break;
case WM_KEYUP:
{
switch((int)wParam)
{
case VK_LEFT:
KEY[LEFT] = 0;
break;
case VK_RIGHT:
KEY[RIGHT] = 0;
break;
case VK_UP:
KEY[UP] = 0;
break;
case VK_DOWN:
KEY[DOWN] = 0;
break;
}
}
break;
Oh, and is it good practice to draw and update the player ship in the WM_KEYDOWN case? well, not is it GOOD practice, is it BAD practice?
The only thing you should do in the case of a key press is just change its state. Also I would update anything like movement or position here. Drawing should be done independently of input, so you should be drawing in your main loop.
Main loop meaning? WM_TIMER? Msg loop?
no, by main loop I mean in your message dispatch loop in WinMain, unless your updating based on time, but i would use bool for and set it to true when its time to update, false after updating (reset to true when timer goes off again......)Quote:
Originally posted by Leeman_s
Main loop meaning? WM_TIMER? Msg loop?