Files
2026-10-05 11:27:21 +02:00

29 lines
769 B
C++

#include "Keyboard.h"
#include "CursesObj.h"
#include "curses.h"
Keyboard::Keyboard() {
CursesObj::Instance(); // Force initialization
nodelay(stdscr, FALSE); // Default to block on getch
}
bool Keyboard::isCharAvail() {
nodelay(stdscr, TRUE); // getch must not block for this polling
int c; // DON'T make this 'char'; 'ERR' may be an 'int' - on some systems,
// just like 'EOF'
bool charWaiting = (c = getch()) != ERR; // If getch returns ERR, no char
// waiting, otherwise, next char is
// returned
if (charWaiting)
ungetch(c); // We got a char; put it back! (We just want to know if there
// is one waiting.)
return charWaiting;
}
char Keyboard::getChar() { return getch(); }