chore: Add course material
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#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(); }
|
||||
Reference in New Issue
Block a user