|
We're glad you came by, but you might find what you're looking for elsewhere. TI-Basic Developer is not the site it once was. While its information on commands and other calculator features remains almost second-to-none, its forum, archives, and even hosting service, Wikidot, have been decaying for years. The calculator community would love to see what you're working on, or help you in your next coding adventure, but TI-Basic Developer is no longer the place to do it. Instead, you should head over to Cemetech (primarily American) or TI-Planet (primarily international). Both are active, well-established forums with their own archives, chatrooms, reference material, and abundant coding tools and resources. We'll see you there, we hope. |
Returns the last keypress.
getKey()
Menu Location
Starting from the program editor:
- Press F3 to enter the I/O menu.
- Press 7 to paste getKey().
This command works on all calculators.
3 bytes
The getKey() command returns the key code of the last keypress. If no key was pressed since the program, function, or expression started running, or since the last getKey() command, getKey() returns 0. It's important to note that once getKey() is used, the keypress is forgotten — even if it's used in the same line! So most of the time you want to store the result of getkey to a variable to use it.
The keypresses that getKey() deals with factor in modifier keys, such as 2nd or alpha. Because of this, it will not respond to the modifier keys pressed by themselves.
This example code using getKey() is commonly used in programs that wait for the user to press a key:
:0→key
:While key=0
: getKey()→key
:EndWhileAdvanced Uses
Although the key codes are given in a table on this website, and are listed in your manual, it may be more convenient to write a short function to return key codes for you:
:keycode()
:Func
:Local k
:0→k
:While k=0
: getKey()→k
:EndWhile
:k
:EndFuncIf you run the function keycode(), it will wait for you to press a key. When you press it, it will return the key code. This function may also be a convenient subroutine in a program that requires waiting for a key in several different places.
