• Advertisement

Archived

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

If i want handle the WM_KEYDOWN for two bottons...?

This topic is 5493 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

Ok if I push one botton WM_KEYDOWN event it start function(): LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: return 0; case WM_KEYDOWN: function() ; return 0; so in the function() i switch if it is button ''A'' or Space or ''S'' and so on.... (only one pressed botton) it is so: function(WPARAM wParam) { switch(wParam) { case VK_LEFT: HandleLeftArrow(); break; case VK_RIGHT: HandleRightArrow(); break; case ''Z'': HandleZ(); break; but if i want handle 2 pressed buttons how i can do?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
GetAsyncKeyState();

Share this post


Link to post
Share on other sites
What is GetAsyncKeyState(); ?? How do work it?

Can you give me some good tutorial or istructions abaut DirectInput?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you are already handling two pressed buttons, aren''t you?

or do you mean to detect key combos?
keep an array keys[256] of all keys.. in WM_KEYDOWN, set corresponding entry to 1, and in WM_KEYUP, set it to 0. in WM_KEYDOWN, if you get a ''C'', check if keys[VK_CONTROL] == 1, if so you got a Ctrl-C.

Not the best way to do it but should work.

Share this post


Link to post
Share on other sites
yes but if i push A and X at the same time how i understand?
i sholud get ''A'' code and ''X'', but how?

Share this post


Link to post
Share on other sites
Well you could just make a variable like this:

keydown[256];

Check the WM_KEYDOWN, and for each case do keydown[key] = TRUE;

After this line do if (keydown[otherkey] = TRUE) do_stuff;

You get me? It''s pretty basic but it works. And about your questions about what is GetAsyncKeyState() and where to find good DirectInput tutorials, for info on certain functions or whatever browse to msdn.microsoft.com and search for the function with the search option. Succes guaranteed. For DirectInput tutorials, have a look at the DirectX SDK help files... As simple as that...

Share this post


Link to post
Share on other sites
The simplest way is to use lots of if statments rather than a case statment -

if (key1)
{}

if(key2)
{}

will ctach both whereas a case statment would only do one of them (the first one it came across)

Share this post


Link to post
Share on other sites
it should be:

if (key1) && (key2)
{
// If it is push key1 and in the same tile key2 so do this
}


Is it correct?

Share this post


Link to post
Share on other sites
When you''re using WM_KEYDOWN you will NEVER get two keys at the same time, you will always get one after the other.

If you don''t want to look inside GetAsyncKeyState and want to stick with WM_KEYDOWN, then you have to implement some buffering.

Take a bool array of 256 entries (for sure), and in WM_KEYDOWN set the corresponding entry to true, and in WM_KEYUP to false.

So in WM_KEYDOWN you set your array entry and after that you can check your array for pressed keys.

This is not the best solution, and not optimal either, but it will work. (I suggest DirectInput, if it is an option to you).

Regards,
Endurion

Share this post


Link to post
Share on other sites
Can u give me some others suggests abaut GetAsyncKeyState?

what is the best solution?

Share this post


Link to post
Share on other sites
call your input function every loop while passing in the message parameters.

bool keyUp;
void OnKey(DWORD wParam, UINT message, DWORD lParam)
{
switch( wParam )
{
case VK_UP:
keyUp = (WM_KEYDOWN == message);
break;
case VK_DOWN:
keyDown = (WM_KEYDOWN == message);
break;
}
}

This way your bool will always hold the correct value for the key. It's what i've been using for a while anyhow.

return Neff;

[edited by - neff on February 10, 2003 4:53:05 PM]

Share this post


Link to post
Share on other sites

  • Advertisement