home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 2.ddi / TOOLS.2 / EXAMPLES / KEYCTRL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  2.5 KB  |  94 lines

  1. /**
  2. *    KEYCTRL.C    Simple example of Turbo C TOOLS key control
  3. *            functions.
  4. *
  5. *  Version    6.00 (C)Copyright Blaise Computing Inc. 1987, 1989
  6. *
  7. **/
  8.  
  9. #include <bkeybrd.h>
  10. #include <butil.h>
  11. #include <bvideo.h>
  12. #include <ctype.h>
  13. #include <stdio.h>
  14.  
  15.         /* Function prototypes.                 */
  16. void main(void);
  17. void key_control(KB_DATA *);
  18.  
  19.         /* Global variables.                    */
  20. int columns;
  21.  
  22. void main()
  23. {
  24.     int  final_key;
  25.     int  num_scrolled;
  26.     int  mode, active_page;
  27.     char user_response[41];
  28.  
  29.         /* Remember the number of columns so that the key   */
  30.         /* control function will know where to display the  */
  31.         /* time.                        */
  32.     scmode(&mode, &columns, &active_page);
  33.  
  34.     puts("Please enter your message  (Press Enter to terminate):");
  35.  
  36.         /* Now install the key control function and get a   */
  37.         /* response from the user.                */
  38.     b_key_ctrl = key_control;
  39.     kbquery(user_response, sizeof(user_response), &final_key,
  40.         &num_scrolled);
  41.  
  42.         /* Echo the user's response.                        */
  43.     puts("\nYour message:");
  44.     puts(user_response);
  45. }
  46.  
  47.  
  48. /**
  49. *
  50. * Name        KEY_CONTROL -- Key control function to convert all
  51. *                   letters to upper case & display the
  52. *                   the current time.
  53. *
  54. * Synopsis    To be called only as a key control function by KBQUERY.
  55. *
  56. * Description    This function gains control from KBQUERY between every
  57. *        poll of the keyboard.  Each time an alphabetic key is
  58. *        hit, it is converted to upper case and returned to the
  59. *        caller.  Regardless of whether a key is hit, the
  60. *        current time of day is displayed in the upper right
  61. *        hand corner of the screen.
  62. *
  63. * Returns    Nothing.
  64. *
  65. **/
  66.  
  67. void key_control(pkey_data)
  68. KB_DATA *pkey_data;
  69. {
  70.     long tick_count;
  71.     int  hours, minutes, seconds, hundredths;
  72.     char time[9];
  73.  
  74.         /* If a key was struck and it was alphabetic,        */
  75.         /* convert it to upper case.  Note that the key     */
  76.         /* code is changed to match the new character code. */
  77.     if (pkey_data->key_found)
  78.     {
  79.     if (isalpha(pkey_data->key_seq.character_code))
  80.     {
  81.         pkey_data->key_seq.character_code =
  82.         toupper(pkey_data->key_seq.character_code);
  83.         pkey_data->key_seq.key_code =
  84.         kbscanof(pkey_data->key_seq.character_code);
  85.     }
  86.     }
  87.  
  88.         /* Now get the current time of day and display it.  */
  89.     utgetclk(&tick_count);
  90.     uttk2tim(tick_count, &hours, &minutes, &seconds, &hundredths);
  91.     sprintf(time, "%d:%02d:%02d", hours, minutes, seconds);
  92.     vidspmsg(0, columns - strlen(time), SC_BLACK, SC_WHITE, time);
  93. }
  94.