Responsive input with inkey$? How?

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

Responsive input with inkey$? How?

Post by Fabrizio Caruso » Sat Mar 02, 2019 1:29 pm

Hi everyone!
I am struggling to get my little BASIC 10-liner game to detect key-presses in a more responsive way: ... ectrum.bas

In my code I am doing something like:
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?


0 x

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

Re: Responsive input with inkey$? How?

Post by djnzx48 » Sun Mar 03, 2019 3:02 am

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.
0 x

Post Reply