// // Programmer: Craig Stuart Sapp // Creation Date: Sat Jan 1 20:39:33 PST 2005 // Last Modified: Sat Jan 1 20:44:45 PST 2005 // Filename: ...midiio/doc/windowsmidi/compkey/compkey.c // URL: http://midiio.sapp.org/doc/windowsmidi/compkey/compkey.c // Syntax: C; Visual C/C++ 5/6 // // Description: The example program shows how to read a computer // keyboard keypress in real-time in Windows. // When you press a key on the computer keyboard, a message // is printed which shows which key was pressed. // #include /* include for kbhit() and getch() functions */ #include /* for printf() function */ int main(void) { int ckey; // storage for the current keyboard key being pressed printf("Press \"q\" to quit.\n"); while (1) { // event loop if (kbhit()) { // If a key on the computer keyboard has been pressed ckey = getch(); printf("The computer key pressed was: %c\n", (char)ckey); if (ckey == 'q') break; } } return 0; } /* Windows I/O functions used in this program: * * int kbhit(void) -- Returns true if a key on the computer keyboard has * been pressed, or false if no key has been pressed. * int getch(void) -- Returns the key which has been pressed on the computer * keyboard. Returns -1 if there was not key press. */