10-01-2021, 04:30 PM
Trying to write a simple program to check each key switch on the keyboard as I'm not sure keys like ESC, LF, etc. are working and just don't do anything in BASIC or they aren't working.
Idea is something like this:
10 a$=key$:if a$="" then goto 10
20 print "ASCII code: ";asc$(a$):print ""
30 goto 10
I basically swiped this from p133 of the 16K MW Basic manual I found online:
KEY{$}
KEY$ returns a string depending on whether or not a key on the keyboard has been pressed.
If no key has been pressed since the last KEY$ call (or line input), the null string (length 0) is returned.
If a key has been pressed, the one-character string corresponding to that key is returned.
The characters which are received using the KEY$ function are NOT automatically displayed on the screen, allowing such things as "TURTLE GRAPHICS" and real time games which do not require the RETURN key to pressed and don’t stop when waiting for a key.
Because the time taken to look at the keyboard is very short, the KEY$ function is usually examined in some sort of loop.
Example:
00100 A0$="" : REM clear string to accumulate
00110 A1$=KEY$ : IF A1$="" THEN 110 : REM get key
00120 A0$=A0$+A1$ : REM add this key to A0$
00130 IF ASC(A1$)<> 32 THEN 100 : REM wait for a space
00140 PRINT A0$ : REM view captured string
On Amstrad's Locomotive BASIC I would've used INKEY$ so I assume KEY$ is the equivalent.
But on my MW BASIC 5.10 it doesn't like line 10 ... "integer string error".
So I changed it to ... a=key$ ... even though KEY$ returns a string, and then got an "unknown function error".
Okay, so that makes sense ... MW BASIC 5.10 doesn't have that function I guess?
Reading through the manual I didn't see any version number it related to.
I'm going to search more online for a manual, but in case anyone can point out a simple solution ...
Idea is something like this:
10 a$=key$:if a$="" then goto 10
20 print "ASCII code: ";asc$(a$):print ""
30 goto 10
I basically swiped this from p133 of the 16K MW Basic manual I found online:
KEY{$}
KEY$ returns a string depending on whether or not a key on the keyboard has been pressed.
If no key has been pressed since the last KEY$ call (or line input), the null string (length 0) is returned.
If a key has been pressed, the one-character string corresponding to that key is returned.
The characters which are received using the KEY$ function are NOT automatically displayed on the screen, allowing such things as "TURTLE GRAPHICS" and real time games which do not require the RETURN key to pressed and don’t stop when waiting for a key.
Because the time taken to look at the keyboard is very short, the KEY$ function is usually examined in some sort of loop.
Example:
00100 A0$="" : REM clear string to accumulate
00110 A1$=KEY$ : IF A1$="" THEN 110 : REM get key
00120 A0$=A0$+A1$ : REM add this key to A0$
00130 IF ASC(A1$)<> 32 THEN 100 : REM wait for a space
00140 PRINT A0$ : REM view captured string
On Amstrad's Locomotive BASIC I would've used INKEY$ so I assume KEY$ is the equivalent.
But on my MW BASIC 5.10 it doesn't like line 10 ... "integer string error".
So I changed it to ... a=key$ ... even though KEY$ returns a string, and then got an "unknown function error".
Okay, so that makes sense ... MW BASIC 5.10 doesn't have that function I guess?
Reading through the manual I didn't see any version number it related to.
I'm going to search more online for a manual, but in case anyone can point out a simple solution ...