|
Cant control key rate |
cpayette
Member #7,348
June 2006
|
I have a problem. I'm using P to pause my game but the user has to have lightning skills not to have the keyboard read multiple presses. Basically, its hard to pause the game because the input is so fast. I tried set_keyboard_rate(0,0); and it still refreshes just as fast.
Ive tried creating a static variable to snapshot the current time, then compare the snapshotted time to the newest current time, but it doesn't seem to work as my timer counts to 240 and resets. Am I using the wrong functions here to get input? Honestly, if allegro had some way to just check for Key UP, it'd be easy. Every other library I've worked with has had keyup and keydown checks, and I've used keyup when I don't want the action repeating. Edit: I guess I should show this too:
|
gnolam
Member #2,030
March 2002
|
Quote: I tried set_keyboard_rate(0,0); and it still refreshes just as fast. That only affects buffered input (i.e. keypresses read with readkey()/ureadkey()). Anyway: void do_input_stuff(void) { static int repeat_counter = 0; if ((key[KEY_FOO] && (repeat_counter == 0)) { do_stuff(); repeat_counter = 10; } if (repeat_counter > 10) repeat_counter--; } Or see this thread. [EDIT]Fixed the code. -- |
cpayette
Member #7,348
June 2006
|
Awesome that helped a lot. I came close to that but couldn't quite get it. FYI, in case this post helps anyone else, make sure you do this: if(repeat_counter > 0) Thanks again! |
gnolam
Member #2,030
March 2002
|
Ah, yes. The dangers of typing example code directly into the code box. -- |
|