class ofApp : public ofBaseApp {
ofxKeyEventManager manager;
int value{0};
void minus() { value--; };
public:
void setup() {
manager.addListener('+', [this] { value++; }, "increment value");
manager.addListener('-', std::bind(&ofApp::minus, this), "decrement value");
manager.enableDraw();
}
void draw() {
manager.draw(10, 10);
// draw
// '+': increment value
// '-': decrement value
}
};
setup with name
- name: manager's name
ofxKeyEventManager &addPressListener(int key, std::function<void()> callback, const std::string &description)
ofxKeyEventManager &addReleaseListener(int key, std::function<void()> callback, const std::string &description = "no description")
add listener for key
with callback
-
key: char code
-
callback: is called when press/release key
-
description: event description
-
returns itself. can method chain.
ofxKeyEventManager &addListener(int key, std::function<void()> callback, const std::string &description)
same as addPressListener
remove listener for key
- key: char code
same as removePressListener
call listener manually
- enable/disable to listen event
- return
true
if listen now elsefalse
- enable/disable draw()
- get drawing status
- mute/unmute a specified press/release listener
- get mute status for key given.
draw descriptions
draw descriptions with registered order
draw specified description for key
given
dump out descriptions of listener that registered to all of ofxKeyEvent object to console.
- many update
- thx @nariakiiwatani
- initial
MIT License.
- ISHII 2bit [bufferRenaiss co., ltd.]
- ishii[at]buffer-renaiss.com
Please create a new issue if there is a problem. And please throw a pull request if you have a cool idea!!