/* * KEYBOARD */ #include #include #include #include "global.h" #include "kbd.h" static FLAG double_esc = FALSE; /*************************************************************************** * * (...) * ***************************************************************************/ void kbd_any_key() { kbd_flush(); printf("Press any key to continue...\n"); while (!kbhit()) ; getch(); /* Discard key */ } /*************************************************************************** * * (...) * ***************************************************************************/ void kbd_flush() { double_esc = FALSE; // Init to no double click while (kbhit()) /* Flush kbd buffer */ if (getch() == 0x1B) // ESC? { delay (1000); // Wait at least one sec if (kbhit() && (getch() == 0x1B)) // ESC again? double_esc = TRUE; // Indicate double click } } /*************************************************************************** * * (...) * ***************************************************************************/ FLAG kbd_get_yn(char *str) { kbd_flush(); printf("%s (Y/N)? ",str); while (TRUE) switch (getch()) { case 'Y': case 'y': printf("Y\n"); return (TRUE); case 'N': case 'n': printf("N\n"); return (FALSE); default: break; } return (FALSE); } /*************************************************************************** * * (...) * ***************************************************************************/ FLAG kbd_esc(char *str) { if (kbhit()) // Some key pressed? if (getch() == 0x1B) // ESC? { delay (1000); // Wait at least one sec if (kbhit()) // Some key pressed again? if (getch() == 0x1B) // ESC again? { double_esc = TRUE; // Indicate double click return (FALSE); } double_esc = FALSE; // Init to no double click return (kbd_get_yn(str)); } double_esc = FALSE; // Init to no double click return (FALSE); } /*************************************************************************** * * (...) * ***************************************************************************/ FLAG kbd_double_esc(void) { kbd_flush(); return (double_esc); }