Input String Advanced.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Custom string input example enabling the CHAR menu
  2. #define USE_TI89 // Compile for TI-89
  3. #define USE_TI92PLUS // Compile for TI-92 Plus
  4. #define USE_V200 // Compile for V200
  5. #define MIN_AMS 100 // Compile for AMS 1.00 or higher
  6. #define SAVE_SCREEN // Save/Restore LCD Contents
  7. #include <tigcclib.h> // Include All Header Files
  8. short captured;
  9. CALLBACK void CaptureHandler(EVENT *ev)
  10. {
  11. if (ev->Type == CM_STRING)
  12. captured = *(ev->extra.pasteText);
  13. }
  14. void InputStr(char *buffer, unsigned short maxlen)
  15. {
  16. SCR_STATE ss;
  17. short key;
  18. unsigned short i = 0;
  19. buffer[0] = 0;
  20. SaveScrState (&ss);
  21. do
  22. {
  23. MoveTo (ss.CurX, ss.CurY);
  24. printf ("%s_ ", buffer);
  25. // Note that two spaces are required only if the F_4x6 font is used
  26. do
  27. {
  28. key = ngetchx ();
  29. if (key == KEY_CHAR && i < maxlen)
  30. {
  31. EVENT ev;
  32. captured = 0;
  33. ev.Type = CM_KEYPRESS;
  34. ev.extra.Key.Code = key;
  35. EV_captureEvents (CaptureHandler);
  36. EV_defaultHandler (&ev);
  37. EV_captureEvents (NULL);
  38. }
  39. } while (!captured);
  40. if (key == KEY_CHAR && i < maxlen)
  41. buffer[i++] = captured;
  42. if (key >= ' ' && key <= '~' && i < maxlen) buffer[i++] = key;
  43. if (key == KEY_BACKSPACE && i) i--;
  44. buffer[i] = 0;
  45. } while (key != KEY_ENTER);
  46. }
  47. // Main Function
  48. void _main(void)
  49. {
  50. char s[20];
  51. clrscr ();
  52. InputStr (s, 20);
  53. printf ("\n%s", s);
  54. ngetchx ();
  55. }