30.11.2010 - initial commit
This commit is contained in:
39
pikbdlistener.cpp
Normal file
39
pikbdlistener.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "pikbdlistener.h"
|
||||
|
||||
|
||||
PIKbdListener::PIKbdListener(KBFunc slot, void * data_): PIThread() {
|
||||
ret_func = slot;
|
||||
data = data_;
|
||||
#ifdef __WIN32__
|
||||
hIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
GetConsoleMode(hIn, &smode);
|
||||
SetConsoleMode(hIn, ENABLE_PROCESSED_INPUT);
|
||||
#else
|
||||
struct termios term;
|
||||
tcgetattr(0, &term);
|
||||
sterm = term;
|
||||
term.c_lflag &= ~(ECHO | ICANON) | NOFLSH;
|
||||
tcsetattr(0, TCSAFLUSH, &term);
|
||||
#endif
|
||||
start();
|
||||
}
|
||||
|
||||
|
||||
PIKbdListener::~PIKbdListener() {
|
||||
#ifdef __WIN32__
|
||||
SetConsoleMode(hIn, smode);
|
||||
#else
|
||||
tcsetattr(0, TCSANOW, &sterm);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIKbdListener::run() {
|
||||
#ifdef __WIN32__
|
||||
ReadConsole(hIn, &rc, 1, &ret, 0);
|
||||
#else
|
||||
ret = read(0, &rc, 1);
|
||||
#endif
|
||||
if (ret_func != 0 && ret > 0) ret_func(data, rc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user