The ASCII CODE
command capture a keystroke "on the Fly",
and return the equivalent ASCII code instead of internal SCANCODE
.
This command is a fundamental tool for making programs more interactive.
It allows you to read a character typed by the user without having to press
the enter key.
Unlike other input commands, ASCII CODE
does not require the user to press
Enter to send the character, while the typed character is not displayed on
the screen. It return directly the ASCII code of the typed character, or
a special value (0) if no key was pressed. It is equivalent to write
ASC( INKEY$() )
, but faster, since no string is created. Note that
the reading speed could vary significantly depending on the target.
This command allows you to create simple games in which the user must
press specific keys to control a character or object. It can be used
to create more responsive user interfaces, in which the user can interact
with the program in real time or that respond to certain key combinations,
automating certain operations.
Due to the limitations of 7-bit ASCII encoding, ASCII CODE
could only
read characters in the standard ASCII set. Use SCANCODE
if you need
to be able to detect any key.
= ASCII CODE
IF ASCII CODE = 42 THEN PRINT "ASTERISK has been pressed!" ENDIF
Join BASIC 10Liner Contest with ugBASIC!
An interesting competition is held at the beginning of each year: the
BASIC 10Liner Contest.
It is possible to use ugBASIC to participate in the next
"BASIC10Liner" competition, in the following categories:
ASCII CODE ↔ AsciiCo
If you have found a problem with this keyword, if you think there is a bug or, more
simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!
open an issue
BACK TO KEYWORDS