FANDOM


Here's an example program which provides the code for a custom text entry function (or in other words, a custom and tweak-able equivalent to INPUT). Almost every line is commented, so check out the code if you want to get a better idea of how it works. This sort of text entry is useful when INPUT doesn't perform the way you need it to, as you can control many aspects of the text entry. For instance, once you understand the code, you can do things like restrict entry to only numbers, or make sure the entry isn't longer than a certain length. You can also do things like perform processing on the text while the text is still being written.

How it worksEdit

There are two important variables when working with custom text input: INKEY$() and KEYBOARD. INKEY$() returns the last character pressed on the keyboard which is able to be displayed (so no SHIFT key, DELETE key, etc. Only letters, numbers, and symbols). KEYBOARD returns the key code of the last key pressed on the keyboard, no matter what it is. We could technically do the whole thing without INKEY$() since KEYBOARD is more powerful, but INKEY$() is a nice shortcut. Here's what we do:

  • Keep a variable which will store the text
  • In a loop, append INKEY$() to the text
  • Check the KEYBOARD variable for keys such DELETE. We don't need to worry about things like SHIFT making things capital or not, because INKEY$() takes care of that for us.
  • Check INKEY$() for characters like NEWLINE (the ENTER key), since these actually do show up on the screen, and thus will get appended to our text. In this program, I throw away the ENTER key presses and replace them with a press of the A button (which exits the function and returns the text entered).

That's pretty much all there is to it. Check out the code for more details.

How to useEdit

Append the example program to your program. Remove all the lines before the @TEXTENTRY function. Now you have access to the @TEXTENTRY function.

There are 4 variables which you'll need to set in order to use the function. You can set them wherever you like, and as many times as you like, but they must be set at least once before you call your first GOSUB @TEXTENTRY.

  • TXTX - The X location of the text input
  • TXTY - The Y location of the text input
  • TXTMAX - The maximum length of the text input (32 or less)
  • TXTLINE - Whether or not to underline the text input field (1 or 0)

Check out the code as-is to see an example of how to use the @TEXTENTRY function.

Text Entry Example

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.