Archived

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

Testing for arrow keys..

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

If you are programming for directx then use would use direct input, if you are programming for windows then you could use the WM_KEYDOWN message, if you are programming for dos you could start thinking about programming for directx.


/CMN

Share this post


Link to post
Share on other sites
quote:
Original post by Julio

isn''t MSVC++ a Windows only compiler? if not, what other os''s does it support?




I think he meant to ask whether he was making a console program, a windows program using just windows API calls, or a directX windows program.



Masters Software

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you want to check key asynchronously (i.e. independently of your messageloop you can use

SHORT GetAsyncKeyState(INT vKey)

with a parameter of VK_LEFT, VK_RIGHT, VK_UP or VK_DOWN.
The value returned has the MSB set if the key is pressed and the LSB set if the key has been pressed sometime after the last call to GetAsyncKeyState

Share this post


Link to post
Share on other sites
In a windows app without using DirectInput I insert the following in my callback message handler.

switch(uMsg)
{
case WM_KEYDOWN:
switch (wParam)
{
case VK_UP: break;
case VK_DOWN: break;
case VK_LEFT: break;
case VK_RIGHT: break;
case VK_CLEAR: break;
case VK_F1: break;
case VK_F2: break;
case VK_F3: break;
case VK_F4: break;
case VK_F5: break;
case VK_F6: break;
case VK_F7: break;
case VK_F8: break;
case VK_F9: break;
case VK_ESCAPE: break;
}
default: return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
return 0L;
}

Hope this helps.

IceFire

Share this post


Link to post
Share on other sites
Just use this macro:

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

then in your prog, just go:

if (KEY_DOWN(VK_RIGHT)
{
// do whatever
}

Hope that helps

Share this post


Link to post
Share on other sites
Well, yes, the virtual key codes would work for a windows environment, as stated above.

You could also use DirectInput.

But, when it gets down to the nitty-gritty, I believe that you could also test for those keys using their ASCII values, which are 028 through 031.

I think that these are correct:

028 = UP ARROW
029 = DOWN ARROW
030 = RIGHT ARROW
031 = LEFT ARROW

Of course, you might want to double-check those.

- Goblin
"In order to understand the full depth of mankind, you must first seperate the word into its component parts: 'mank' and 'ind'."

Share this post


Link to post
Share on other sites