GET: Your Keyboard Key Catcher

GET: Your Keyboard Key Catcher

Tired of waiting for the INPUT command to do its thing? Want more granular control over keyboard input? Look no further than the GET command! This nimble tool lets you snatch individual characters from the keyboard buffer as soon as they're pressed, giving you lightning-fast responsiveness and the power to create custom input routines. Think of it as your keyboard ninja!

Syntax

GET <string variable>

Where: - <string variable>: A string variable (ending in $) that will store the captured character.

Applications

The GET command is your secret weapon when:

  • You need real-time input: Create games where characters react instantly to key presses, or build custom text editors with smooth cursor movement.
  • You want to validate input: Check each character as it's typed to ensure it's valid before accepting it.
  • You're creating custom interfaces: Design menus and prompts that respond to specific keys without requiring the user to press Enter.

Code Examples

1. Simple Character Input:

10 GET K$ 
20 IF K$ <> "" THEN PRINT K$; :rem Print the character if a key was pressed
30 GOTO 10                    :rem Keep checking for input

This loop continuously waits for a key press and prints the character to the screen.

2. Detecting Arrow Keys:

10 GET K$
20 IF K$=CHR$(145) THEN PRINT "Up arrow pressed"   :rem CHR$(145) is the up arrow code
30 IF K$=CHR$(17) THEN PRINT "Down arrow pressed"  :rem CHR$(17) is the down arrow code
40 GOTO 10

This snippet demonstrates how to use GET and CHR$ to detect specific key presses (in this case, the up and down arrow keys).

GET in the Wild: The Typing Tutor Maestro

Imagine you're creating a typing tutor program for the Commodore 64. You could use GET to capture each keystroke as it's typed, providing instant feedback on accuracy and speed, helping users improve their typing skills.

Don't let your keyboard input lag behind! With GET, you can grab characters the moment they're pressed, giving your programs a level of responsiveness that INPUT just can't match. It's like having a direct line to your keyboard, allowing you to create truly interactive experiences on your Commodore 64. So unleash the power of GET and let your fingers do the talking!

Important Note: The GET command reads characters from the keyboard buffer, which can hold up to 10 characters. If the buffer is full, GET will wait until a character is removed before returning. You can use the INPUT# command with file number 0 to clear the keyboard buffer.


Privacy Policy

Let's be honest, we collect some data. But we promise not to sell it, we'll mostly use it to improve our service. You can read the nitty-gritty details below, but be warned, it uses big words that lawyers like (we don't judge).

By using our service, you agree to this privacy policy. This disclaimer strikes a balance between lightheartedness and informing users that they should still read the full privacy policy if they choose.