How can I get input from the keyboard?

Input: Keyboard and Link Next

Q: How I can get input from the keyboard?
A: There is a lot of method how you can make such routine. This is quite easy if you are a C programmer. The easiest but the worst method is to use gets function from stdio.h header file: gets does not do any buffer length checking. In previous releases of TIGCCLIB, it did not even allow any editing facitilities (even backspace key would not work), but this is no longer the case. A better idea is to use getsn which does avoid buffer overflows. But if you want to control what exactly is done by the input routine (for example, you may or may not want to allow opening the CHAR menu), you'll have to make a custom keyboard input routine. For example, I usually used the following routine, which is good enough for many purposes (example "Input String"):
// Custom string input example

#define USE_TI89              // Compile for TI-89
#define USE_TI92PLUS          // Compile for TI-92 Plus
#define USE_V200              // Compile for V200

#define MIN_AMS 100           // Compile for AMS 1.00 or higher
#define SAVE_SCREEN           // Save/Restore LCD Contents

#include <tigcclib.h>         // Include All Header Files

// Custom String Input Function
void InputStr(char *buffer, unsigned short maxlen)
{
  SCR_STATE ss;
  short key;
  unsigned short i = 0;
  buffer[0] = 0;
  SaveScrState (&ss);
  do
    {
      MoveTo (ss.CurX, ss.CurY);
      printf ("%s_  ", buffer);
        // Note that two spaces are required only if the F_4x6 font is used
      key = ngetchx ();
      if (key >= ' ' && key <= '~' && i < maxlen)
        buffer[i++] = key;
      else if (key == KEY_BACKSPACE && i)
        i--;
      buffer[i] = 0;
    } while (key != KEY_ENTER);
}

// Main Function
void _main(void)
{
  char s[20];
  clrscr ();
  InputStr (s, 20);
  printf ("\n%s", s);
  ngetchx ();
}
Especially, if very good editing facitilities are required, the best idea is to use routines from the textedit.h header file. These routines are extremely powerful and fully customizable. Alternatively, you can also use routines from dialogs.h, especially DialogAddRequest.


See also: Do you have the function that gets called when you do InputStr in TI-Basic?, How can I make a keyboard input function that allows you to bring up a menu?, getsn