stdin_nonBlock
stdin_nonBlock allows for non-blocking access to stdin
Say you've a loop in main() that should do something regardless of whether a keypress occurs... but also process keypresses when they occur. The normal getchar()-based functions cause the loop to stop and wait until data is available, stdin_nonBlock does not. Instead, it returns immediately. If data's not available, it returns -1.
Unfortunately, it does not (yet?) handle individual keypresses... each entry needs to be followed by "Return" before stdin_nonBlock will recognize the data.
// Basic Functionality:
// NOTE: this still requires return be pressed before the data's available
// Return *will* be emitted by stdinNB_getChar()
// So in most cases we'll get at least two chars (in two calls)
// main()
// {
// stdinNB_init();
//
// while(1) {
// int kbChar = stdinNB_getChar();
// switch(kbChar) {
// case -1:
// //do nothing
// break;
// case 'a': ...
// }
//
// ..Do other main-loop things, without waiting for keyboard input..
// }
// }
FILES:
stdin_nonBlock.h
test.c