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
[BASIC] How to read from the keyboard buffer?
-
- Drutt
- Posts: 11
- Joined: Sat Mar 02, 2019 1:16 pm
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: [BASIC] How to read from the keyboard buffer?
Use the LAST K system variable maybe (23560)?
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
-
- Drutt
- Posts: 11
- Joined: Sat Mar 02, 2019 1:16 pm
Re: [BASIC] How to read from the keyboard buffer?
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.
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.
-
- Drutt
- Posts: 11
- Joined: Sat Mar 02, 2019 1:16 pm
Re: [BASIC] How to read from the keyboard buffer?
Maybe I could do something like:
let c=peek(23560): if c<>13 then print c: POKE 23560,13
let c=peek(23560): if c<>13 then print c: POKE 23560,13
-
- Drutt
- Posts: 11
- Joined: Sat Mar 02, 2019 1:16 pm
Re: [BASIC] How to read from the keyboard buffer?
THANKS A LOT!
I solved the problem by reading from 23560 and resetting it once I consume the input.
I solved the problem by reading from 23560 and resetting it once I consume the input.
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: [BASIC] How to read from the keyboard buffer?
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.