Multiwindow keyPressed Event can it be done?

Hi im trying to move a part of my code to another window this part draw a list of songs that you can change by pressing key down
but i was wondering do i have to add a listener in the main.h like this
and if i do this i get another err
to listen to keystrokes ??

I wonder this because when i run the program it works i see two windows but if i try to select some song i get a crass::
on the if that says ::Thread 1 :EXEC_BAD_MEmory_Acceses(code=1 ,address=0x5fff)

void ofApp::keyPressed(int key){
    switch (key){
        case OF_KEY_DOWN:
            if (dir.size() > 0 && sounds[current].isLoaded()){ <<<Thread 1 :EXEC_BAD_MEmory_Acceses(code=1 ,address=0x5fff)
                current %= dir.size();

any help will be much appreciated

1 Like

I thinks that it is not possible, you should create another header file with its own method , check the example multiWindowExample from folder event

hey @GinesMendoza, i try that at the end i just generate the list into ofxDatGui instead of creating another window just for that …

thanks anyway

@cyrstem that is a good option to save fps in your app, if you create another windows the fps of your app will be lower. On the other hand, if you have two windows you will be able to have the control panel in a window and the visual in another window, I usually do that for live performances :slight_smile:

1 Like

Yeah that was my idea too, i just didn’t knew how to put a list of files into a GUI, i was just drawing them into the sketch as texts, now i have a lot of Guis in another window

this is my way to have all panel controls on the main window and the visual on the second window

void ofApp::draw() {



		for (int i = 0; i < particleSystem.size(); i++) {
			Particle& cur = particleSystem[i];

			particleSystem.addRepulsionForce(cur, particleNeighborhood, particleRepulsion, mesh, multiple);





		shader.setUniform1f("ksectors", Ksectors);
		shader.setUniform1f("kangleRad", ofDegToRad(kangle));
		shader.setUniform2f("kcenter", 0.5*currentWithWindow, 0.5*currentHeightWindow);
		fbo.draw(0, 0, currentWithWindow, currentHeightWindow);


glColor3f(0, 0, 0);
ofDrawBitmapString("particles number: " + ofToString(particleSystem.size()), ofVec2f(32.0f, 32.0f));
ofDrawBitmapString("fps: " + to_string((int)ofGetFrameRate()), ofVec2f(32.0f, 52.0f));
ofDrawBitmapString("particleNeighborhood: " + to_string((int)particleNeighborhood), ofVec2f(32.0f, 72.0f));
ofDrawBitmapString("multiple: " + to_string((int)multiple), ofVec2f(32.0f, 92.0f));
ofDrawBitmapString("lifeTime: " + to_string((int)lifeTime), ofVec2f(32.0f, 112.0f));
ofDrawBitmapString("backgroundColor: " + to_string((int)backgroundColor), ofVec2f(32.0f, 132.0f));

gui.setPosition(32, 152);

void ofApp::drawSecondWindow(ofEventArgs & args) {
		fbo2.draw(0, 0, currentWithWindow, currentHeightWindow);

int main( ){

	ofGLFWWindowSettings settings;

	settings.width = 600;
	settings.height = 600;
	settings.setPosition(ofVec2f(100, 100));
	settings.resizable = true;
	shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings);

	settings.width = PROJECTOR_RESOLUTION_X;
	settings.height = PROJECTOR_RESOLUTION_Y;
	settings.setPosition(ofVec2f(0, 40));
	settings.resizable = true;
	settings.multiMonitorFullScreen = true;
	settings.shareContextWith = mainWindow;
	shared_ptr<ofAppBaseWindow> secondWindow = ofCreateWindow(settings);

	shared_ptr<ofApp> mainApp(new ofApp);
	ofAddListener(secondWindow->events().draw, mainApp.get(), &ofApp::drawSecondWindow);

	ofRunApp(mainWindow, mainApp);
1 Like