Files
pip/pikbdlistener.h
2011-10-09 22:23:52 +04:00

50 lines
1.0 KiB
C++

#ifndef PIKBDLISTENER_H
#define PIKBDLISTENER_H
#include "pithread.h"
#ifndef WINDOWS
#include <termios.h>
#endif
#define WAIT_FOR_EXIT while (!PIKbdListener::exiting) msleep(1);
typedef void (*KBFunc)(char, void * );
class PIKbdListener: public PIThread {
friend class PIConsole;
public:
// slot is any function format "void <func>(char, void * )"
PIKbdListener(KBFunc slot = 0, void * data = 0);
~PIKbdListener() {terminate(); end();}
void enableExitCapture(char key = 'Q') {exit_enabled = true; exit_key = key;}
void disableExitCapture() {exit_enabled = false;}
bool exitCaptured() const {return exit_enabled;}
char exitKey() const {return exit_key;}
bool isActive() {return is_active;}
void setActive(bool yes = true);
static bool exiting;
private:
void begin();
void run();
void end();
KBFunc ret_func;
char rc, exit_key, is_active;
bool exit_enabled;
void * data;
#ifdef WINDOWS
DWORD ret;
void * hIn;
DWORD smode, tmode;
#else
int ret;
struct termios sterm, tterm;
#endif
};
#endif // PIKBDLISTENER_H