hypnotic401
24th January 2013, 18:53
Hello all,
I made a custom event filter for my application and installed it on my instance of QApplication. However, I noticed some strange behavior. When I press a key (once and it doesnt get held down) I do get the KeyPress event (I check for auto repeat first and if its false I handle the event other wise let event processing continue and this is because if someone holds down a key I do not want it sending out multiple keypress events and keyrelease events), I do not receive a KeyRelease event until I press the key again at which I do not receive the KeyPress. Any Ideas of what I could be doing wrong?
Below is my code that handles key events (I do some other checks above to make sure the widget in question or more specifcally the qobject in question has focus).
I pass emsg (which is an internal struct that I use to propagate events to other modules), I am using windows 7 64 bit but compiling and linking with Qt in 32 bit.
This is the use case of pressing a key once:
//q is pressed and immediately released
switch (event->type()) {
case QEvent::KeyPress:
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if (!keyEvent->isAutoRepeat()) {
//It falls in here fine the first go around but never gets to released
emsg.wParam = keyEvent->key();
emsg.lParam = keyEvent->modifiers();
} else {
keyEvent->ignore();
return false;
}
break;
}
case QEvent::KeyRelease:
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if (!keyEvent->isAutoRepeat()) {
//it never gets here but if I press q again it falls in here and not in keypress
emsg.wParam = keyEvent->key();
emsg.lParam = keyEvent->modifiers();
} else {
keyEvent->ignore();
return false;
}
break;
}
}
I made a custom event filter for my application and installed it on my instance of QApplication. However, I noticed some strange behavior. When I press a key (once and it doesnt get held down) I do get the KeyPress event (I check for auto repeat first and if its false I handle the event other wise let event processing continue and this is because if someone holds down a key I do not want it sending out multiple keypress events and keyrelease events), I do not receive a KeyRelease event until I press the key again at which I do not receive the KeyPress. Any Ideas of what I could be doing wrong?
Below is my code that handles key events (I do some other checks above to make sure the widget in question or more specifcally the qobject in question has focus).
I pass emsg (which is an internal struct that I use to propagate events to other modules), I am using windows 7 64 bit but compiling and linking with Qt in 32 bit.
This is the use case of pressing a key once:
//q is pressed and immediately released
switch (event->type()) {
case QEvent::KeyPress:
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if (!keyEvent->isAutoRepeat()) {
//It falls in here fine the first go around but never gets to released
emsg.wParam = keyEvent->key();
emsg.lParam = keyEvent->modifiers();
} else {
keyEvent->ignore();
return false;
}
break;
}
case QEvent::KeyRelease:
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if (!keyEvent->isAutoRepeat()) {
//it never gets here but if I press q again it falls in here and not in keypress
emsg.wParam = keyEvent->key();
emsg.lParam = keyEvent->modifiers();
} else {
keyEvent->ignore();
return false;
}
break;
}
}