GLBasic User Manual

Main sections

INKEY$

a$=INKEY$( )



This command returns the key the user has pressed rather than a key-ID as the KEY( ) function does. e.g. If the user presses the key 'b', INKEY$ returns 'b' where using KEY( ) results in KEY(48)=1.

The KEY( ) function is faster, but having the actual key pressed returned can sometimes be more useful (as seen in the below INPUT function example).

The enter key returns "\n", the backspace key "\b".

Sample:
 
// ------------------------------------------------------------- //
// INPUT via INKEY$ - Input with starfield background
// ------------------------------------------------------------- //

// Setup Starfield data
DIM spd[640]
DIM sy[640]
FOR x=0 TO 639
spd[x]=RND(3)+1
sy[x]=-RND(480)
NEXT

name$=""
WHILE TRUE
IF KEY(14)
name$=MID$(name$, 0, LEN(name$)-1) // Backspace
ELSE
in$=INKEY$()
IF in$<>"" THEN name$=name$+in$
ENDIF
PRINT name$, 0, 100
GOSUB ShowStarfield
SHOWSCREEN
WEND
END


// ------------------------------------------------------------- //
// -=# SHOWSTARFIELD #=-
// ------------------------------------------------------------- //
SUB ShowStarfield:
LOCAL x
FOR x=0 TO 639
c=spd[x]
y=sy[x]
y=y+c
IF y>480 THEN y=0
sy[x]=y
c=c*64 -1
SETPIXEL x, y, RGB(c, c, c)
NEXT
ENDSUB // SHOWSTARFIELD

See also...