Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » readkey() and sticking

This thread is locked; no one can reply to it. rss feed Print
readkey() and sticking
SkaxCo
Member #8,323
February 2007

I'm trying to use readkey to move a character across the screen. If you hold down the key, it backlogs the keyboard. Is there any way to clear the keyboard buffer? Like keyboard_clear() or something like that?

Kauhiz
Member #4,798
July 2004

clear_keybufR.T.F.M...

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

SkaxCo
Member #8,323
February 2007

Thanks

Kauhiz
Member #4,798
July 2004

Sorry, edited

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Albin Engström
Member #8,110
December 2006
avatar

I'm putting in a little question: when would clear_keybuf be needed? because i've never used it and everything works great..?

Kauhiz
Member #4,798
July 2004

...Please just RTFM, please!

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Kris Asick
Member #1,424
July 2001

If you're using readkey() for movement, EXPECT backlog.

You want to be reading the key[] array instead if you want constant movement.

If however you want the ability to move single spaces AND constantly, one method you can do is to check both readkey() and key[] at the same time and only move the character if BOTH return the appropriate value.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Albin Engström
Member #8,110
December 2006
avatar

Kris Asick: Noted, thanks.

Bill Morris
Member #3,734
July 2003

For some applications, you might want to set the delay and repeat rates, with set_keyboard_rate(delay, repeat). Default is 250, 33 (milliseconds). You might want to set it for high speed and use rest() to slow it down where necesary, to vary the speed as the program may require.

But clear_keybuf() is definitely useful for the problem you mentioned. I use in my text editors to reprevent buffer overload when scrolling.

gnolam
Member #2,030
March 2002
avatar

... no. For the situation the OP mentioned, the key[] array is the way to go. And you basically never want to use rest() except to yield to the OS.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Go to: