home *** CD-ROM | disk | FTP | other *** search
- /**
- * KEYCTRL.C Simple example of Turbo C TOOLS key control
- * functions.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1987, 1989
- *
- **/
-
- #include <bkeybrd.h>
- #include <butil.h>
- #include <bvideo.h>
- #include <ctype.h>
- #include <stdio.h>
-
- /* Function prototypes. */
- void main(void);
- void key_control(KB_DATA *);
-
- /* Global variables. */
- int columns;
-
- void main()
- {
- int final_key;
- int num_scrolled;
- int mode, active_page;
- char user_response[41];
-
- /* Remember the number of columns so that the key */
- /* control function will know where to display the */
- /* time. */
- scmode(&mode, &columns, &active_page);
-
- puts("Please enter your message (Press Enter to terminate):");
-
- /* Now install the key control function and get a */
- /* response from the user. */
- b_key_ctrl = key_control;
- kbquery(user_response, sizeof(user_response), &final_key,
- &num_scrolled);
-
- /* Echo the user's response. */
- puts("\nYour message:");
- puts(user_response);
- }
-
-
- /**
- *
- * Name KEY_CONTROL -- Key control function to convert all
- * letters to upper case & display the
- * the current time.
- *
- * Synopsis To be called only as a key control function by KBQUERY.
- *
- * Description This function gains control from KBQUERY between every
- * poll of the keyboard. Each time an alphabetic key is
- * hit, it is converted to upper case and returned to the
- * caller. Regardless of whether a key is hit, the
- * current time of day is displayed in the upper right
- * hand corner of the screen.
- *
- * Returns Nothing.
- *
- **/
-
- void key_control(pkey_data)
- KB_DATA *pkey_data;
- {
- long tick_count;
- int hours, minutes, seconds, hundredths;
- char time[9];
-
- /* If a key was struck and it was alphabetic, */
- /* convert it to upper case. Note that the key */
- /* code is changed to match the new character code. */
- if (pkey_data->key_found)
- {
- if (isalpha(pkey_data->key_seq.character_code))
- {
- pkey_data->key_seq.character_code =
- toupper(pkey_data->key_seq.character_code);
- pkey_data->key_seq.key_code =
- kbscanof(pkey_data->key_seq.character_code);
- }
- }
-
- /* Now get the current time of day and display it. */
- utgetclk(&tick_count);
- uttk2tim(tick_count, &hours, &minutes, &seconds, &hundredths);
- sprintf(time, "%d:%02d:%02d", hours, minutes, seconds);
- vidspmsg(0, columns - strlen(time), SC_BLACK, SC_WHITE, time);
- }