18.03.2013 - Bug fixes, add in/out speed diagnostic to PIProtocol, fixed PIConsole tab switch segfault, PIObject EVENT / EVENT_HANDLER mechanism update - new EVENT macros that use EVENT_HANDLER with raiseEvent implementation.
This allow compile check event for CONNECT and use EVENT as CONNECT target, also raise event now is simple execute EVENT function.
This commit is contained in:
24
pikbdlistener.h
Executable file → Normal file
24
pikbdlistener.h
Executable file → Normal file
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Keyboard grabber for console
|
||||
Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2013 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
|
||||
@@ -29,29 +29,39 @@
|
||||
|
||||
typedef void (*KBFunc)(char, void * );
|
||||
|
||||
/// events:
|
||||
/// keyPressed(char key, void * data)
|
||||
///
|
||||
/// handlers:
|
||||
/// void enableExitCapture(char key = 'Q')
|
||||
/// void setActive(bool yes = true)
|
||||
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;}
|
||||
EVENT_HANDLER(PIKbdListener, void, enableExitCapture) {enableExitCapture('Q');}
|
||||
EVENT_HANDLER1(PIKbdListener, void, enableExitCapture, char, key) {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);
|
||||
EVENT_HANDLER(PIKbdListener, void, setActive) {setActive(true);}
|
||||
EVENT_HANDLER1(PIKbdListener, void, setActive, bool, yes);
|
||||
|
||||
EVENT2(PIKbdListener, keyPressed, char, key, void * , data)
|
||||
|
||||
static bool exiting;
|
||||
|
||||
|
||||
private:
|
||||
void begin();
|
||||
void run();
|
||||
void end();
|
||||
|
||||
|
||||
KBFunc ret_func;
|
||||
char exit_key;
|
||||
bool exit_enabled, is_active;
|
||||
@@ -65,7 +75,7 @@ private:
|
||||
int ret;
|
||||
struct termios sterm, tterm;
|
||||
#endif
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // PIKBDLISTENER_H
|
||||
|
||||
Reference in New Issue
Block a user