|
@@ -233,3 +233,37 @@ void testKb2()
|
233
|
233
|
|
234
|
234
|
reset_keypress();
|
235
|
235
|
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+// Based on: // From: http://www.flipcode.com/archives/_kbhit_for_Linux.shtml
|
|
239
|
+
|
|
240
|
+int cmIsKeyWaiting()
|
|
241
|
+{
|
|
242
|
+ static const int STDIN = 0;
|
|
243
|
+ static bool initialized = false;
|
|
244
|
+ struct timeval timeout;
|
|
245
|
+ fd_set rdset;
|
|
246
|
+
|
|
247
|
+ if (! initialized)
|
|
248
|
+ {
|
|
249
|
+ // Use termios to turn off line buffering
|
|
250
|
+ struct termios term;
|
|
251
|
+ tcgetattr(STDIN, &term);
|
|
252
|
+ term.c_lflag &= ~ICANON;
|
|
253
|
+ tcsetattr(STDIN, TCSANOW, &term);
|
|
254
|
+ setbuf(stdin, NULL);
|
|
255
|
+ initialized = true;
|
|
256
|
+ }
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+ FD_ZERO(&rdset);
|
|
260
|
+ FD_SET(STDIN, &rdset);
|
|
261
|
+ timeout.tv_sec = 0;
|
|
262
|
+ timeout.tv_usec = 0;
|
|
263
|
+
|
|
264
|
+ // time out immediately if STDIN is not ready.
|
|
265
|
+ return select(STDIN + 1, &rdset, NULL, NULL, &timeout);
|
|
266
|
+
|
|
267
|
+}
|
|
268
|
+
|
|
269
|
+
|