29.07.2011 - fundamental new

This commit is contained in:
peri4
2011-07-29 08:17:24 +04:00
parent b21a0496cd
commit 29190ea465
49 changed files with 4704 additions and 1052 deletions

View File

@@ -1,9 +1,27 @@
#include "pikbdlistener.h"
bool PIKbdListener::exiting;
PIKbdListener::PIKbdListener(KBFunc slot, void * data_): PIThread() {
#ifdef __WIN32__
hIn = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(hIn, &smode);
#else
struct termios term;
tcgetattr(0, &term);
sterm = term;
#endif
is_active = true;
ret_func = slot;
data = data_;
PIKbdListener::exiting = exit_enabled = false;
start();
}
void PIKbdListener::begin() {
//cout << "list begin" << endl;
#ifdef __WIN32__
hIn = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(hIn, &smode);
@@ -11,19 +29,8 @@ PIKbdListener::PIKbdListener(KBFunc slot, void * data_): PIThread() {
#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
}
@@ -34,6 +41,16 @@ void PIKbdListener::run() {
#else
ret = read(0, &rc, 1);
#endif
if (ret_func != 0 && ret > 0) ret_func(rc, data);
if (exit_enabled && rc == exit_key) PIKbdListener::exiting = true;
if (ret_func != 0 && ret > 0 && is_active) ret_func(rc, data);
}
void PIKbdListener::end() {
//cout << "list end" << endl;
#ifdef __WIN32__
SetConsoleMode(hIn, smode);
#else
tcsetattr(0, TCSANOW, &sterm);
#endif
}