Skip to main content
gamedev.net
🔒 Locked

detect keystrokes

Started by webspynner_99 Sep 3, 2000 at 11:26 AM 3 replies 900+ views
Original Post
webspynner_99
webspynner_99
How can i detect a key stroke that isn''t a regular character, something like the arrow keys? also, how do I detect key strokes without the user haveing to hit enter? I''m using C in Borland C++ 4.52. If you have an answer that uses C++, I can easily switch to C++ instead of C. I have a cannon, and it launches potatoes. You will bow down to me, or you will eat mashed potatoes at 60mph. EAT AT WAFFLE HOUSE! The Spyders Web JavaScript Games. Check out the JavaScript RPG!
baskuenen
baskuenen
If you''re programming for Win32, you could try virtual keys (WM_KEYDOWN message, with keys: VK_LEFT, VK_RIGHT, ...), or you could add an accelerator resource, and catch the WM_COMMAND...

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

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

if (KEYDOWN(VK_RIGHT))
{
//CODE

}
else if (KEYDOWN(VK_LEFT))
{
//CODE

}
............

You get the idea

Edited by - Foxtrot on September 3, 2000 8:08:21 PM

Edited by - foxtrot on September 3, 2000 8:08:57 PM
webspynner_99
webspynner_99
okay...yes I am doing for win32. Umm... I''m fairly new at this, so you''ll have to be brutally obvious. I''ll see if I can get it to work. Are there any files I have to include?
foxtrot
foxtrot
Hmmmm....
I can''t remember at the moment. I''m new to C++ myself. I''m at
work right now. When I get home (8 hours from now) I''ll look
and see. But untill then. try winuser.h and make sure user32.lib
is included also. Like I said I''m new too. So if this doesn''t
work I appologize. Good Luck.
Where to use the code is up to you.

Foxtrot

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.