any help would be appreciated
any help would be appreciated
If I understand you're meaning, you might try:
Where keyVar is a variable you made earlier to store the key that was pressed. Basically this is implementing a keyboard buffer for you so you don't have to handle the keyboard at such a low level.PHP Code:
if(keypressed())
keyVar=readkey();
-Justin
Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/
puting "if (keyvar=KEY_SPACE)" in side that if statment slowed down the rate of key reading but it still reconized the key being held down. I want it so it will only recognize the key as pressed once and then you have to let go of the key and press it again to recognize it as pressed again.
void set_keyboard_rate(int delay, int repeat);
sounded like it might do the right thing but the documentation was pretty vauge on how to use it.
the other way i could see doing this is that once a key has been pressed it is ignored untill the key is released but can you read if the key is up in allergo. If not would it work to use GetAsyncKeyState()
Don't replace the if statement in the code I gave, add your if statment after it. And it should be:if (keyvar=KEY_SPACE)
if (keyvar == KEY_SPACE)
otherwise you are assigning keyvar the value of the space bar being pressed, not testing if it is.
Modified snippet:
Hope that works. If not, (haven't tried this one yet..) then sounds like you may have to impliment it yourself. There are lots of ways to do this, one may be to create an array that will be indexed by the significant key.PHP Code:
int keyvar;
...
if(keypressed())
keyvar=readkey();
else keyvar=0;
if(keyvar == KEY_SPACE)
{...}
There are obviously some optimizations to be done to that... but just trying to give the idea.PHP Code:
bool kbhandle[256]; // Handle all ASCII keys.
// if key pressed:
kbhandle[keyvar]=1;
// if key released:
kbhandle[keyvar]=0;
if(keyvar == KEY_SPACE && kbhandle[KEY_SPACE] == 0)
...
-Justin
Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/
I dont use allegro, but i think i know what your saying, to check if it has been hit once, but no being held down?
You can do something like:
Code:if(key_is_down==FALSE) keypressed=FALSE; if (key_is_down==TRUE && keypressed==FALSE) { keypresses=TRUE; do whatever }
this is good for loops
make sure you installed the allegro keyboard handler
it is kinda like kbhit(), where it doesn't block when you use it. That makes it ideal for gameloops and stuff like that. It is fast too.Code:if (key[KEY_LEFT]) { ... }