I'm working with the directional key state macros "key[KEY_UP]" type thing. It works well if you are moving a bit map around the screen. However, not so good if you just want to read which cell a person is moving to. I won't bore everyone with the details of the game. but here is a rough idea of what I'm doing

1)Player has a board (like checkers, sorta) with a current status.2) The player can move Up, Down, L/R, one square.3) Once direction is decided, the player's piece is moved4) Board redrawn5) continue at step 1

Anyways, my problem is when the up (in this case) arrow is hit, it actually buffers several times and I've got no way of emptying the buffer. I've tried clear_buf but didn't do anything. I've tried a while(keypressed); loop thinking it would run through the loop until a key press wasn't detected but it locks in the loop. I know I can use readkey() and use letters like a,s,d,w, but would rather use the arrow keys. Unless there is a way I haven't found yet, I can't get readkey to do anything with arrow key scans.

In short, is there a way of emptying the key buffer using arrow keys or is there a difference key scan that works with readkey()/clear_buf and arrow keys.

The problem with changing the key up value or using a secondary value, is it doesn't eliminate the scanned keys. IE

User its key up,the buffer readskeyupkeyupkeyupkeyupkeyup

So if I change the keyup to read false (0) then the second scan key up comes back and says true. Key in mind, when running a key[XXX] while loop, the loop runs continously. So changing the internal key[UP] to 0 , only works for that one trip through the loop. The next time through the loop and it scans the key board, it's going to see there are more key[ups] in waiting and will react accordingly. I have to empty the buffer some how.

However, I will trial these just to make sure my understanding of the process isn't wrong.

It looked to me like he had cloned variables that he was altering, not the actual Allegro key array.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

Sorry if my paraphrasing of the actual KEY array command confused those trying to help.

The whole key pressed Vs key released may give me a work around as you guys have shown. I did have one concern however, if the Player hits up and then releases, how many times will the combination Up and press be true before the player can release the key?

I'm hoping the solution will allow me...1)to read an up key. 2)Stop the player input / involvement3) Correct board according to direction chosen.4) Return to a clean buffer / condition5) await next directional move.

Again, the only potential issue I can see from the solution, not having tried them, would be if the up and pressed conditions are read 5-6 times before the player turns loose of the key. I guess I could add a third condition that starts false and trues the first time through the if statment. Then when I get key released scan, can falsify it again.

I used to get the same feedback when I did keypress for debugging. I made it so that when a key was pressed it would output debug info to a file. When I opened the file it would have about 5 or so for each key press. Not sure if that is what he is talking about but the code I used was the code from Tomasu's wiki tutorials.

"Can't a man even talk to himself without being interrupted?" -Krull(1983)"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix"Programming == AWESOME the rest is just tools to accomplish it."END OF LINE

Specter Phoenix is correct, When I print something out, it shows the key to hit 4-5 times.

I won't bore everyone with the entire code given I'm just testing different aspects until I have all the components working. But here is essentially what I have (I'm just including one key for the sake of demonstration.

while(key[ESC]){

if(key[KEY_UP]) printf("Yo!");}

this is a little skeleton compared to what I have but the issue is the same. And yes I know I can't see the print out until I drop out of graphics mode. But when I do I see 4-5 "Yo"s when I actually only hit the up arrow for a second. This tells me one of two things have to be true.1) Either the loop runs so fast that in just touching the up arrow once it hold the condition "if(key[KEY_UP]" true for 4-5 times though the loop, or2) the key buffer holds 3-4 more up arrow keys so that each time through the loop the condition is true, until the buffer runs out.

So now I either need to either change the condition of #1 to look for a key release (as suggested above) after the first key[UP] is true or if #2 is true I need a way of depleting the key buffer given I can't find a way to clear on command.

"Can't a man even talk to himself without being interrupted?" -Krull(1983)"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix"Programming == AWESOME the rest is just tools to accomplish it."END OF LINE

Yeah, but I'm not asking for help, just illustrating what is happening. I've learned asking for help is a waste because you get too many varied answers and normally none of them are close to your coding style so you end up still lost.

I got to the point, over the years, to where I just act like I had a clue what they said and then skip what I was getting help with and come up with something else to code. I was doing an address book, and got stuck on something, so moved on to pong, got stuck on pong and moved to learning perl, got stuck on perl and learned ruby, got stuck their and went back to coding simple apps that I knew how to do.

"Can't a man even talk to himself without being interrupted?" -Krull(1983)"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix"Programming == AWESOME the rest is just tools to accomplish it."END OF LINE

Which brings up the question: What is the point of a wiki if the examples are wrong and never corrected with the "100 times" repeat so you didn't have to say it 100 times?

[REVISION]Tomasu, not attacking your code or anything. Just pointing out the idiocy of "we have said it 100 times" and yet if the topic has been addressed that much you would think they would have done a fix or posted a new page. Then instead of "we said it 100 times" the can say "look here <wiki url>" or even sig them .

"Can't a man even talk to himself without being interrupted?" -Krull(1983)"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix"Programming == AWESOME the rest is just tools to accomplish it."END OF LINE

No, because you've failed to understand the code. What it does is set a flag for each direction if a specific key is being pressed, and then unset it when the key is released. If the flags are set, then various things happen, otherwise they don't.

The key[] array in Tomasu's example is not the same as the key[] array in A4.

LennyLen: I understand the code, but I was trying to point out that even with Tomasu's A5 code it still prints out multiple lines with one press. I simply copied and pasted the code, added file i/o to each key, and when I just pressed it once I got the 3 or 4 lines per press.

"Can't a man even talk to himself without being interrupted?" -Krull(1983)"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix"Programming == AWESOME the rest is just tools to accomplish it."END OF LINE

LennyLen: I understand the code, but I was trying to point out that even with Tomasu's A5 code it still prints out multiple lines with one press. I simply copied and pasted the code, added file i/o to each key, and when I just pressed it once I got the 3 or 4 lines per press.

That's how it's supposed to work with the Wiki example. It's a movement example, so it's supposed to continue to move for as long as the key is held down.

That's how it's supposed to work with the Wiki example. It's a movement example, so it's supposed to continue to move for as long as the key is held down.

Yeah but I'm not holding it down. I just do one quick keypress of say left and the file io shows 3 or 4 outputs for just one quick keypress. Like if I press 'a' to make a and had file io attached to that key that outputs say "Hello", I would have an output file that would have Hello Hello Hello Hello just for one press of a.

"Can't a man even talk to himself without being interrupted?" -Krull(1983)"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix"Programming == AWESOME the rest is just tools to accomplish it."END OF LINE

As far as the hardware is concerned, that is holding it down. It's a lot quicker than you are.

Is there a way to fix it? Rather annoying to sift through a file of 100 lines of debug data when each one has 3 unneeded duplicates.

"Can't a man even talk to himself without being interrupted?" -Krull(1983)"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix"Programming == AWESOME the rest is just tools to accomplish it."END OF LINE