![]() In fact, the ReadKey function is somewhat more complicated than described above. For example: Chr(27) is equivalent to #27. Note, that character constants may be writtenĪs the corresponding ASCII code, preceded by the number sign(#). Inversely, you can convert a character to the corresponding ASCII code using the function Ord. Knowing the ASCII code, you can convert it into a character, using the function Chr. The output, you get, depends on the code page used. Printable characters are in the range from 32 to 126, 127 is the ESC key, characters above 127 give no output if the system codepage is actually 65001 (UTF8), otherwise, ASCII code 0 corresponds to the NULL character, ASCII codes from 1 to 31 are control or special characters, Keys? Characters are internally stored as ASCII codes. No problem for letters, numbers and symbols, but how to deal with special and command keys, like ENTER, ESC, TAB, or the arrow The last keyboard key pressed may be retrieved by using the function ReadKey (also defined in the Crt unit). Write('Hit any key to terminate the program. Terminating a program by hitting any key In the Crt unit, thus we must specify this unit in the uses clause. If we want to terminate the program with any keystroke, we can use the Boolean function KeyPressed within a loop. Write('Hit ENTER to terminate the program. The simplest way to do so, is to tell the user to push ENTER to exit a simple Readln may be used in this case: // Terminating a program by hitting the ENTER key Thus, if you want to be sure to view the program's output, you'll have to pause the program before it reaches theĮnd of the code. On MS Windows, no idea if this applies to Linux, too). If you run a command line program by double-clicking the executable, the Command Prompt window is automatically closed when the program terminates (this is how it works ![]() How to do it in a Lazarus GUI application?Ĭatching key strokes in Free Pascal command line programs. How to proceed to get the corresponding character or code, in the case a special or control character was pressed? How to do it in a simple command line program and How the program or application notices, when a key is pressed? This tutorial is about reacting, when the user strokes a key on the keyboard. Catching keystrokes in Free Pascal programs and applications.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |