Responsive input with inkey$? How?

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
Fabrizio Caruso
Drutt
Posts: 11
Joined: Sat Mar 02, 2019 1:16 pm

Responsive input with inkey$? How?

Post by Fabrizio Caruso »

Hi everyone!
I am struggling to get my little BASIC 10-liner game to detect key-presses in a more responsive way:
https://github.com/Fabrizio-Caruso/Sinc ... ectrum.bas

In my code I am doing something like:
LET s=CODE INKEY$
LET lr = (s=108)-(s=106): LET ud = (s=107)-(s=105)
LETpx = px+lr: LET py = py+ud
but for some reason, INKEY sometimes skips some key-presses.
Is there a better way to read the keyboard status in BASIC?

Image

Fabrizio
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Responsive input with inkey$? How?

Post by djnzx48 »

You could try using CHR$ PEEK 23560 instead of INKEY$ (or use LET s=PEEK 23560). It returns the last pressed key instead of the currently pressed key, so it could detect keystrokes that would normally be skipped. The downside is you can't use it to tell when no key is being pressed, but you could maybe clear it with POKE 23560,0 after you've checked for a key.
Post Reply