Created
February 2, 2023 21:30
-
-
Save stungeye/23580e5fef648e2798c069d9e7f83816 to your computer and use it in GitHub Desktop.
Detecting Keys and Keycodes in Openframeworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
//-------------------------------------------------------------- | |
void ofApp::setup() { | |
ofAddListener(ofGetWindowPtr()->events().keyPressed, this, | |
&ofApp::keycodePressed); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update(){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
} | |
void ofApp::keycodePressed(ofKeyEventArgs& e){ | |
cout << "KEY : " << e.key << endl; | |
cout << "KEYCODE : " << e.keycode << endl; | |
cout << "MODIFIERS : " << e.modifiers << endl; | |
if (e.keycode == 83 ) { | |
if (e.modifiers == 0) { | |
cout << "Plain old s\n"; | |
} else if (e.modifiers == OF_KEY_SHIFT) { | |
cout << "SHIFT-s\n"; | |
} else if (e.modifiers == OF_KEY_ALT) { | |
cout << "ALT-s\n"; | |
} else if (e.modifiers == OF_KEY_CONTROL) { | |
cout << "CTRL-s\n"; | |
} | |
} | |
} | |
//-------------------------------------------------------------- | |
void ofApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseMoved(int x, int y ){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseDragged(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mousePressed(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseReleased(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseEntered(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::mouseExited(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::windowResized(int w, int h){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::gotMessage(ofMessage msg){ | |
} | |
//-------------------------------------------------------------- | |
void ofApp::dragEvent(ofDragInfo dragInfo){ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
class ofApp : public ofBaseApp{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
void keyReleased(int key); | |
void mouseMoved(int x, int y ); | |
void mouseDragged(int x, int y, int button); | |
void mousePressed(int x, int y, int button); | |
void mouseReleased(int x, int y, int button); | |
void mouseEntered(int x, int y); | |
void mouseExited(int x, int y); | |
void windowResized(int w, int h); | |
void dragEvent(ofDragInfo dragInfo); | |
void gotMessage(ofMessage msg); | |
void keycodePressed(ofKeyEventArgs& e); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment