Page 1 of 1

[BASIC] How to read from the keyboard buffer?

Posted: Sat Mar 23, 2019 8:33 pm
by Fabrizio Caruso
Hi!

I am struggling with the input in the Spectrum version of my BASIC game "Mines":
https://github.com/Fabrizio-Caruso/Sinc ... -10-liners

I need to read the last key-pressed in a loop without stopping if no key is pressed.
I don't want to miss key-presses.
I currently use "LET S = CODE INKEY$" but this works randomly because
it seems not to read from the keyboard buffer. It seems it is only reading the current keyboard status.
So if by chance the key was pressed and released just before, then the last key pressed is lost.

What is the correct way to read the keyboard in a "buffered way"?

Fabrizio

Re: [BASIC] How to read from the keyboard buffer?

Posted: Sat Mar 23, 2019 8:51 pm
by Ast A. Moore
Use the LAST K system variable maybe (23560)?

Re: [BASIC] How to read from the keyboard buffer?

Posted: Sat Mar 23, 2019 11:47 pm
by Fabrizio Caruso
How do I detect no ket pressed with 23560.
I want to get the last key pressed only once and not forever.
It is for an interactive non-stopping action game.

So if a key is pressed I need to detect it and not miss it but I need to detect it just once.

In principle INKEY seems to do that but it does not in my case.
It misses many key-presses. I suppose it fails to detect keys pressed before INKEY$ execution because
they are not buffered.

Re: [BASIC] How to read from the keyboard buffer?

Posted: Sat Mar 23, 2019 11:56 pm
by Fabrizio Caruso
Maybe I could do something like:
let c=peek(23560): if c<>13 then print c: POKE 23560,13

Re: [BASIC] How to read from the keyboard buffer?

Posted: Sun Mar 24, 2019 12:46 am
by Fabrizio Caruso
THANKS A LOT!

I solved the problem by reading from 23560 and resetting it once I consume the input.

Re: [BASIC] How to read from the keyboard buffer?

Posted: Sun Mar 24, 2019 8:10 am
by Ast A. Moore
;)