Question

I found that the keyPress event is never fired until the key is actually released on Linux . This behavior is different on vista. Here is a piece of code from my application.

The difference happens when I do the following sequence: 1) CTRL key down, 2) hold it for a while 3) release it.

On Linux, nothing is printed out till the release.i.e. you'll not see anything till 3), then you'see "notify::KeyPressed" and "notify::KeyReleased".

On Vista, after 1), you'll see "notify::KeyPressed", then in 2), you can detect that the CTRL is down with QApplication::keyboardModifier().testFlag(Qt::ControlModifier). then after 3), you'll see "notify::KeyReleased".

I think what happens on vista is what I expected. How can I fix the problem on Linux and why it happens this way?

Thanks for your help!

MyApplication::QApplication
{
   bool notify(Object * receiver, QEvent * event) {
       try{
           if (event->type() == QEvent::KeyPress) {
               std::cout<<"notify::KeyPressed"<<endl;
           }

           if (event->type() == QEvent::KeyRelease) {
               std::cout<<"notify::KeyReleased"<<endl;
           }


            return QApplication::notify( receiver, event );
       }
       catch ( ... ) {
          std::cerr << "Unknown Exception caught: " << ends;

       }
       return false;

    }
}
Was it helpful?

Solution

Finally found the problem. I'm using a virtual machine running on a blade. When you connect to the blade, the client tool, has an option: "Send First Key", by default, it is disabled, so when connected to the virtual machine, when you pressed CTRL, (remember the first key is disabled), you do not get the "keyPress" event! After I enabled that, it starts to work as expected!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top