[Resolved] How to make my program not exit on escape keypress?

Hello,

I used the code generator app for code::blocks on windows. My app is exiting when I press escape, and I don’t want it to. Why is it doing this? I have not entered any code related to exiting on keypresses yet.

Relevant code is pasted below.

    //--------------------------------------------------------------
void ofApp::setup() {
    ttFont.loadFont(fontDir+"segoeUI.ttf",14,true,true,true);
//set FPS cap
    ofSetFrameRate(60); //Actual integer seems to be half of the framerate limit. IE: 60 will give a cap of ~120FPS (???)

}

//--------------------------------------------------------------
void ofApp::update() {

}

//--------------------------------------------------------------
void ofApp::draw() {

    if(enableFPS) {

        //Show FPS of window...
        ttFont.drawString(ofToString(ofGetFrameRate()) + "fps", 10, 15);
    }
    ttFont.drawString("enableFPS = "+ ofToString(enableFPS), 200, 200);
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key) {

    cout << "keyPressed " << key << endl;
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key) {

cout << "keyReleased " << key << endl;

    switch(key) {

        case 13:
        case 27:
            cout << "not used for now" << endl;
            break;

        case 257:
            enableFPS = !enableFPS;
            break;

        default:
            cout << "not a used key binding" << endl;
            break;

    }
}

//--------------------------------------------------------------
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::windowResized(int w, int h) {

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg) {

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo) {

}

Under your setup section, add this:

ofSetEscapeQuitsApp(false);

It defaults to be enabled.You didn’t do anything wrong.

1 Like

wow thanks, that was a lot simpler than I expected it would be, lol.