Jump to content
  • Advertisement
Sign in to follow this  
doyleman

key mapping, or whatever it is

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

I was wondering if it is possible to check what button the user pressed. I need to make a ascii like deal, but I'm going to need to run a check if up/down/left/right arrows were pressed, and possibly some others for attacking. If some one can tell me if this is possible, and if it is, what the command is for the keys or such. Thank you in advance; doyle

Share this post


Link to post
Share on other sites
Advertisement
I'm using C++ (sorry for not mentioning that in first post).
I have no idea what an API is, or if I do, I dont know what it stands for, sorry.

Share this post


Link to post
Share on other sites
API stands for application programming interface. In particular I was wondering if you were using DirectInput, SDL, Allegro or something like those.

The problem is that C++ doesn't have any facility to natively detect things like the arrow keys. You need to rely on some other mechanism to read those kinds of keys. Like in Windows you can use the Win32 function GetAsyncKeyState() to determine if one of those keys are down.

Share this post


Link to post
Share on other sites
Strange...
I just finished Tic Tac Toe, and my friend now suggested I try doing some ASCII stuff.
Hm, thanks for the info and all, I'll ask him if he wanted me to do that in C++ or not, and inform him that I am unable to do so with it.

Again, thanks for your help and info :)

Share this post


Link to post
Share on other sites
If all you are doing is checking what key is pressed you cold use macros and the WIN32 API like this:

#define KEYDOWN(VK_CODE) ((GetAsynkKeyCode(VK_CODE) & 0x8000) ? 1 : 0)
#define KEYUP(VK_CODE) ((GetAsynkKeyCode(VK_CODE) & 0x8000) ? 0 : 1)

if (KEYDOWN(VK_RIGHT))
{
// do stuff
}

if (KEYDOWN(VK_LEFT))
{
// do more stuff
}
.
.
.

Share this post


Link to post
Share on other sites
macros and WIN32 API?
Could you perhaps explain what these API's exactly do? or what macros is, etc?

Sorry if this is a strange question, I just like to know what it is people are suggesting and such.

Share this post


Link to post
Share on other sites
These are macros:
#define KEYDOWN(VK_CODE) ((GetAsynkKeyCode(VK_CODE) & 0x8000) ? 1 : 0)
#define KEYUP(VK_CODE) ((GetAsynkKeyCode(VK_CODE) & 0x8000) ? 0 : 1)

Pretty much what they do is where you see something like this
KEYDOWN(VK_RIGHT)
it inserts something like
((GetAsynkKeyCode(VK_RIGHT) & 0x8000) ? 1 : 0)

It saves typing!

WIN32 API is an application programming interface which is usually just a bunch of premade functions and stuff that let you make programs for windows.

I worded that pretty badly but I'm not good at wording things. APIs usually also have more than just functions.

Share this post


Link to post
Share on other sites
Does WIN32 have its own language code, or can it be integrated into dev-c++ or something?
I'd like to just stick with C++ for now, so if I can't key map, I'll tell my friend that I'll do something else.

Share this post


Link to post
Share on other sites
The windows API is not a language. It's a premade set of functions for the C++ language. These functions range from creating and managing windows to grabbing key states. If you were to use a Win32 function you would still be using C++.

It's just that sometimes things are easier when someone else has already written code to do it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!