Reputation: 278
I am writing a simple game in Ocaml, using its module Graphics
to perform drawing and interaction. I came across the problem that Graphics.read_key()
queues all presses for later use, therefore when I hold a key for a while then many "presses" are put into memory. After release the action is still performed.
Is there any way to delete entries from this queue, or just (even better) not queue them at all?
Upvotes: 3
Views: 671
Reputation: 582
THis is problably not the most beautiful solution, but you can use key_pressed
.
This function will return true if a keypress is available.
So once you have read a keypress with read_key
you can flush your queue by calling read_key
until key_pressed
is false and ignoring the result.
(* flush_kp : unit -> unit *)
let flush_kp () = while key_pressed () do
let c = read_key ()
in ()
done ;;
Hope this could help.
Upvotes: 5