I've been working on this for a little while perfecting it here and there. It's not the greatest, but it should fill the need for those that need to do other things while waiting for user input.
I created this because my network routine must continue to communicate with the server or the server times out the connection and drops the client. This allows me to accept input from the player and still keep communicating with the server.
You first call the Init subroutine to clear the variables. Then set your own parameters for where you want the input to be on screen, what you want the prompt to be, and whether or not this is a password entry field.
set display mode 800, 600, 32
disable escapekey
backdrop on
color backdrop 0
sync on: sync rate 0
while not escapekey()
` Initialize the input variables
Gosub GetInputInit
` Set up the x and y screen postions, the input size and the prompt
` Set Pass = 0 for regular text input. Set Pass = 1 for password input
InX = 10: InY = 100: InSize = 20: Prompt$ = "Input -> ": Pass = 0
while not inputdone
Gosub GetInput
` *******************************************
` Call other subroutines you need to run here
` *******************************************
sync
endwhile
text 10,10,MyText$
sync
wait key
end
endwhile
end
GetInputInit:
inputdone = 0
MyText$ = ""
ShowText$ = ""
Return
GetInput:
if scancode() = 28
inputdone=1
repeat:until scancode() = 0
endif
if scancode() = 14
MyText$ = left$(MyText$,len(MyText$)-1)
repeat:until scancode() = 0
endif
if scancode() <> 0
x$=inkey$()
repeat:until x$ <> inkey$()
a = asc(x$)
` Check to see if the input is a space, numbers or A-Z (upper and lower case)
if a = 32 or (a > 47 and a < 58) or (a > 64 and a < 91) or (a > 96 and a < 123)
if len(MyText$) < InSize
MyText$ = MyText$ + x$
endif
endif
endif
ShowText$ = ""
if Pass = 1
while len(ShowText$) < len(MyText$)
ShowText$ = ShowText$ + "*"
endwhile
else
ShowText$ = MyText$
endif
text InX,InY,Prompt$+ShowText$+"_"
Return
I also put a line in to check the ascii code of the input character so you can limit what the user can enter. Right now it's set to only allow the space, numbers, and upper and lower case letters.
Enjoy.