3 - 38 3 - 38
MELSEC-Q
3 LET'S CREATE AND EXECUTE A PROGRAM
The INPUT instruction pauses the program until data is entered and the Enter key is
pressed. When you don not wish to pause the program, the INKEY$ function is used.
the following shows an example program:
Example
…
…
…
A
A
"A" is displayed on the screen when the A key is pressed.
When the A key is released, the screen will be blank again.
No output is displayed on the screen even after execution.
Now press the A key.
10 A$=INKEY$
20 PRINT A$
30 GOTO 10
RUN
Full-byte characters
(Kanji characters)
cannot be used as
an input with the
INKEY$ function.
As you can see, the INKEY$ function checks for the keyboard status and the program
is not be paused. The INKEY$ function uses an empty as the value, and uses the text
as the value when a key is pressed. However, since this value is a character string,
the substituted variable must be a character variable or a character array.
Furthermore, unlike the INPUT function, multiple characters cannot be input once.
Example
Y
Y
Press the key.
10 N=0
20 PRINT "Count in progress"
30 N=N+1
40 K$=INKEY$
50 IF INKEY$= "Y" THEN GOSUB 70
60 GOTO 30
70 PRINT "N= ";N;"
80 RETURN
RUN
Count in progress.
N = 30.
N= 530.
Press the key.
10 PRINT "Press the Y key."
20 K$=INKEY$
30 IF K$= " Y" GOTO 50
40 GOTO 20
50 END
If the INKEY$ function is used to wait for an input as
shown below, the efficiency of multitask execution may
be degraded.
10 PRINT "Press the Y key."
20 K$=INPUT$(1)
30 IF K$<> " Y" GOTO 20
40 END
Use the INPUT$ function in the following case