72 lines
1.9 KiB
C++
Executable File
72 lines
1.9 KiB
C++
Executable File
/*
|
|
PIP - Platform Independent Primitives
|
|
Keyboard grabber for console
|
|
Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#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 setData(void * data_) {data = data_;}
|
|
void setSlot(KBFunc slot_) {ret_func = slot_;}
|
|
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 exit_key;
|
|
bool exit_enabled, is_active;
|
|
void * data;
|
|
#ifdef WINDOWS
|
|
DWORD ret, rc;
|
|
void * hIn;
|
|
DWORD smode, tmode;
|
|
#else
|
|
char rc;
|
|
int ret;
|
|
struct termios sterm, tterm;
|
|
#endif
|
|
|
|
};
|
|
|
|
#endif // PIKBDLISTENER_H
|