Hi!
I am using your excellent BoxInput function (real time text input) but I have a question about it. Is there any way to make it more, um, responsive? It works fine if you type fairly slowly but if you type at any reasonable speed, it drops letters, spaces, etc. The code snippet below is the function (in case you have forgotton it).
I only ask coz the game I am making requires text to be typed very frequently.
FUNCTION BoxInput(Size AS INTEGER X AS INTEGER, Y AS INTEGER)
`x is x coordinate of typing, y is y coord of typing, size is max length of string
LOCAL Key AS STRING
LOCAL LastKey AS STRING
LOCAL CursorPos AS INTEGER
LOCAL CursorWidth AS INTEGER
LOCAL TextWidth AS INTEGER
LOCAL TextHeight AS INTEGER
LOCAL UserText AS STRING
LOCAL CursorTick AS INTEGER
LOCAL Tick AS INTEGER
CursorPos=LEN(UserText)
CursorWidth=TEXT WIDTH(" ")
TextWidth=CursorWidth*Size
TextHeight=TEXT HEIGHT(" ")
CursorTick=TIMER()+500
REPEAT
REPEAT
CLS
BOX X, Y, X+TextWidth, Y+TextHeight, 0, 0, 0, 0
TEXT X,Y,UserText
IF TIMER() > CursorTick
INC CursorTick,500
Tick=1-Tick
ENDIF
IF Tick
IF CursorPos < Size THEN LINE X+(CursorWidth*CursorPos), Y+TextHeight-1, X+(CursorWidth*(CursorPos+1)),Y+TextHeight-1
ENDIF
SYNC
Key=GetKey$()
IF Key = LastKey
Key=""
ELSE
LastKey=Key
ENDIF
UNTIL Key <> ""
IF LEN(Key) > 1 OR ASC(Key) < 32 OR ASC(Key) > 126
IF Key="delete" AND CursorPos < LEN(UserText)
UserText=LEFT$(UserText, CursorPos) + RIGHT$(UserText, LEN(UserText)-CursorPos-1)
ENDIF
IF Key="bs" AND CursorPos > 0
UserText=LEFT$(UserText, CursorPos-1) + RIGHT$(UserText, LEN(UserText)-CursorPos)
DEC CursorPos
ENDIF
IF Key="left" AND CursorPos > 0 THEN DEC CursorPos
IF Key="right" AND CursorPos < LEN(UserText) THEN INC CursorPos
IF Key="home" THEN CursorPos=0
IF Key="end" THEN CursorPos=LEN(UserText)
ELSE
IF LEN(UserText) < Size
UserText=LEFT$(UserText, CursorPos) + key + RIGHT$(UserText, LEN(UserText)-CursorPos)
INC CursorPos
ENDIF
ENDIF
UNTIL Key="enter"
ENDFUNCTION UserText
FUNCTION GetKey$()
LOCAL Key AS STRING
Key=INKEY$()
IF Key=""
Code=SCANCODE()
IF Code > 0
SELECT Code
CASE 200 : Key="up" : ENDCASE
CASE 203 : Key="left" : ENDCASE
CASE 208 : Key="down" : ENDCASE
CASE 205 : Key="right" : ENDCASE
CASE 199 : Key="home" : ENDCASE
CASE 207 : Key="end" : ENDCASE
CASE 211 : Key="delete" : ENDCASE
ENDSELECT
ENDIF
ELSE
SELECT ASC(Key)
CASE 8 : Key="bs" : ENDCASE
CASE 9 : Key="tab" : ENDCASE
CASE 13 : Key="enter" : ENDCASE
ENDSELECT
ENDIF
ENDFUNCTION Key
Thanks
Life is like a penis:
When it's soft you can't beat it, when it's hard you get screwed.