How to detect a keypressed() in a new window? (How to create an event to)

Anyone know how to create an event to detect keypressing in a specific window?

For example: I´m using the event below for detecting keypressing in main window:

void keyPressed() {

    myPort.write(key);
}

But I created an extra window using G4P Gui Builder. The name of this window´s object is "w2". For example, to change this new window background I can use "w2.papplet.background(0);". Is it possible to create an event for detecting keypresses only in this new window I created?

Thanks a lot any help folks!! :)

Tagged:

Answers

  • I learnt hot to do that: Just create a keypress handler(See G4P GWindows class):


    synchronized public void w2_keyPressed(GWinApplet appc, GWinData data, KeyEvent kevent) { 
      println("w2 - key event " + System.currentTimeMillis()%10000000 );
      //
      w2_keyPressed_function();  //see terminal control file
      //
    

    }

    Than create the function to work with pressed key:


    // This method responds to key presses when the 
    //  window is active:
    void w2_keyPressed_function() {    //Execute this function when a key is pressed!(Put it an in event handler)
    
      switch (key) {
      case '\n':        
        blablabla();
        break;
      case 'A':  // If the user types the shift key, don't type anything:
        blablablabla();
        break;
      default: 
        bla();
        break;
      }
    

    }

    Thanks

Sign In or Register to comment.