WM_KYEDOWN alternative?

Started by
11 comments, last by Peter Svensson 21 years, 7 months ago
It''s not that old. I suspect some of the newer keyboards - particularly the USB variants - are finally using designs that eliminate those issues.
Advertisement
Here''s some code... i hope it will look nice with the tags... (never done that before)

Anyways, i appreciate your effort in this matter...

As i said before, i got the same result with GetAsyncKeyState... =( I think it has to be somthing with how windows deals with the WM_KEYDOWN messages. I think that windows instead of sending one message for each keydown-tick it bundels several messges into one and it has a counter that says how many messages this message represent.

Darkor - do you mean like this?
WM_KEYDOWN:
keyList[wParam] = true;
break;
WM_KEYUP:
keyList[wParam] = false;
break;

That is how i do it...
...and this is how the code looks at the moment.


  // The main loop in main =)	DWORD	time = timeGetTime();	bool	done = false;	while (!done)	{		if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )		{			if( !GetMessage( &msg, NULL, 0, 0 ) )			{				if (msg.message == WM_QUIT)					done = true;			}			TranslateMessage(&msg);			DispatchMessage(&msg);		}						// Any key pressed?		if (keyList[0])		{//			if (GetAsyncKeyState(VK_RIGHT) & 0x8000) //				runner.Move( Point( 3, 0 ) );			switch (keyList[0])			{				case VK_LEFT:					path.Move( PathObject::LEFT, &runner );					break;				case VK_DOWN:					path.Move( PathObject::DOWN, &runner );					break;				case VK_RIGHT:					path.Move( PathObject::RIGHT, &runner );					break;				case VK_UP:					path.Move( PathObject::UP, &runner );					break;			}									Point pos = runner.Get();			rect.left	= pos.x-10;			rect.right	= pos.x+10;			rect.top	= pos.y-10;			rect.bottom = pos.y+10;						InvalidateRect( hWnd, &rect, TRUE );					}				while (time+30> timeGetTime());;		time = timeGetTime();			}// And in WinProc...case WM_KEYDOWN:			switch (wParam)			{				case VK_LEFT: 				case VK_RIGHT:				case VK_UP:				case VK_DOWN:					keyList[0] = wParam;					break;				case VK_SPACE:					break;			}			return 0;		case WM_KEYUP:			switch (wParam)			{				case VK_LEFT: 				case VK_RIGHT:				case VK_UP:				case VK_DOWN:						keyList[0] = 0;					break;				case VK_SPACE:					break;			}			break;  





This barely merits an answer, but here goes...

You''re setting keyList[0] to the wParam of the keypress, ONLY WHEN YOU RECEIVE A KEYDOWN MESSAGE, so of course GetAsyncKeyState is dependent on message rates and the way you process them! But that''s not how it''s supposed to be; trash your keyboard handlers in the WndProc altogether and just check each frame whether or not each key is down.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[twitter]warrenm[/twitter]

This topic is closed to new replies.

Advertisement