processing of the result of a INKEY$

Post Reply
Posts: 15
Joined: Tue Dec 10, 2019 12:17 am

processing of the result of a INKEY$

Post by daniel_dlds »


I am doing a text editor in Basic. I have a loop where during a certain count, the current position of the insertion point flashes, its a cursor to indicate to the user where the next letter will appear when typed in the keyboard.
The keys are read by the use of INKEY$. Inside this loop when a count of 25 is reached the character at the insertion point is a dark square (the graphical character), when it reaches 50 it is a space. When nothing is being typed, this implements a flashing cursor.

On one of the lines of the loop (after determining the character of the cursor), i check if INKEY$ is <>"". If it is, then a key has been pressed. I then jump to a subroutine with GO SUB that actually prints the character at the position of the cursor. it then returns and jumps to the beggining of the loop where the current position in the line is incremented.

Now, with this increment, the cursor is supposed to start flashing on the character position to the right of the character that was just typed in. This happens if I type slowly the new text. If I type faster, the current cursor's character is left in the position where the new character would be.

I don't understand this behaviour because :
- I detect a keypress
- I print the letter pressed at position x,y
- I increment the y coordinate
- I print the current cursor character at the new y position that was just incremented

Seems like the key is printed but before the advancement of the y coordinate, the cursor flashes and the key pressed is replaced by it.
But followinf the list I wrote above, how can this happen ?

If someone willing to help. I can put the actual code here (its small), I just have to copy it by hand from the screen to some textfile on my laptop, because I am saving the program to a server using the spectranet interface.

Thanks for any help,
User avatar
Posts: 5196
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: processing of the result of a INKEY$

Post by 1024MAK »

Are you using a string variable to store the value from the INKEY$ function, or using the INKEY$ function independently each time?

Only if you are doing the later, strange things can happen because of the way that the system scans the keyboard and updates the value returned by INKEY$. This keyboard scanning happens independently of the running program. So each time INKEY$ is used you can get a different value.

Hence it’s recommended that at start of the routine to process keyboard input, you use something like:

Code: Select all

Then test or use K$.

ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer being good this year.
Post Reply