Here's a less practical, but more easily followed, example:
That's about as straightforward as the graphical text-entry can get. You need to understand that once you start getting into real-time graphics work, a lot of things that seem trivial aren't necessarily so--but they're not necessarily complex, either. You just need to customize behavior to your own needs, as there isn't really a good analog for the "Input" function in a graphical realm; there are simply too many factors to consider and too many different ways in which any given programmer might want to implement text input.
Strict ' ALWAYS USE STRICT unless you have a very good reason not to. Graphics 640, 480 ' initialize the graphics system. ' declare and initialize variables Local isRunning:Int Local userTypedString:String Local lastCharacter:Int userTypedString$ = "" isRunning = 1 lastCharacter = 0 While isRunning = 1 DrawText "Type something. Click left mouse button to end program.", 10, 10 ' draws instructions to the "back buffer" lastCharacter = GetChar() ' gets the character code of the last key hit. See help on GetChar() for more information. If lastCharacter <> 0 Then ' if GetChar() returned 0, then there was no key pressed, so only add to the user typed string if lastCharacter = 0. userTypedString$ = userTypedString$ + Chr(lastCharacter) ' Chr() converts character codes to their corresponding letters. EndIf DrawText userTypedString$, 10, 24 ' draw the user typed string to the "back buffer". Flip ' draws the "back buffer" to the screen Cls ' clears the "back buffer" FlushMem ' Tells the garbage collector to do its stuff. Do this once per "draw" cycle. If MouseDown(1) > 0 Then ' check to see if the user has clicked their mouse. isRunning = 0 ' if they have, set isRunning to zero, which will exit the While loop and end the program. EndIf Wend
That's about as straightforward as the graphical text-entry can get. You need to understand that once you start getting into real-time graphics work, a lot of things that seem trivial aren't necessarily so--but they're not necessarily complex, either. You just need to customize behavior to your own needs, as there isn't really a good analog for the "Input" function in a graphical realm; there are simply too many factors to consider and too many different ways in which any given programmer might want to implement text input.