key mapping, or whatever it is

Started by
22 comments, last by doyleman 18 years, 8 months ago
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
Advertisement
What programming language are you using, and what API for input?
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.
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.
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 :)
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}...
F-R-E-D F-R-E-D-B-U-R...G-E-R! - Yes!
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.
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.
F-R-E-D F-R-E-D-B-U-R...G-E-R! - Yes!
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.
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.

This topic is closed to new replies.

Advertisement