观察键盘按键按下时的event
void event(QEvent *event)
{
if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
{
QKeyEvent *evt = static_cast<QKeyEvent*>(event);
QString str = "KeyEvent ";
if (evt->key() == Qt::Key_Shift) str += "Shift";
else if (evt->key() == Qt::Key_Control) str += "Ctrl";
else if (evt->key() == Qt::Key_Alt) str += "Alt";
str += event->type() == QEvent::KeyPress ? " Press" : " Release";
str += ", autoRepeat=" + QString(evt->isAutoRepeat() ? "1" : "0");
qDebug() << str;
}
}
短按
KeyEvent “KeyPress” “,autoRepeat=0” //按键按下,autoRepeat=false
KeyEvent “KeyRelease” “,autoRepeat=0” //按键松开,autoRepeat=false
长按
KeyEvent “KeyPress” “,autoRepeat=0” //按键按下第一下,autoRepeat=false
KeyEvent “KeyRelease” “,autoRepeat=1”
KeyEvent “KeyPress” “,autoRepeat=1” //按键按下第二下,autoRepeat=true
KeyEvent “KeyRelease” “,autoRepeat=1”
KeyEvent “KeyPress” “,autoRepeat=1”
KeyEvent “KeyRelease” “,autoRepeat=1” //长按期间会不断发送松开事件,autoRepeat=true
KeyEvent “KeyPress” “,autoRepeat=1”
KeyEvent “KeyRelease” “,autoRepeat=1”
KeyEvent “KeyPress” “,autoRepeat=1”
KeyEvent “KeyRelease” “,autoRepeat=1”
KeyEvent “KeyPress” “,autoRepeat=1”
KeyEvent “KeyRelease” “,autoRepeat=1”
KeyEvent “KeyPress” “,autoRepeat=1”
KeyEvent “KeyRelease” “,autoRepeat=1”
KeyEvent “KeyPress” “,autoRepeat=1”
KeyEvent “KeyRelease” “,autoRepeat=1”
KeyEvent “KeyPress” “,autoRepeat=1”
KeyEvent “KeyRelease” “,autoRepeat=1”
KeyEvent “KeyPress” “,autoRepeat=1”
KeyEvent “KeyRelease” “,autoRepeat=1”
KeyEvent “KeyPress” “,autoRepeat=1”
KeyEvent “KeyRelease” “,autoRepeat=1”
KeyEvent “KeyPress” “,autoRepeat=1”
KeyEvent “KeyRelease” “,autoRepeat=0” //按键松开,autoRepeat=false
组合键
“KeyEvent Alt Press, autoRepeat=0” //Alt、Ctrl、Shift的autoRepeat=0,单独按下不会触发长按
“KeyEvent Press, autoRepeat=0”
“KeyEvent Release, autoRepeat=0”
“KeyEvent Alt Release, autoRepeat=0”
“KeyEvent Ctrl Press, autoRepeat=0”
“KeyEvent Press, autoRepeat=0”
“KeyEvent Release, autoRepeat=0”
“KeyEvent Ctrl Release, autoRepeat=0”
“KeyEvent Shift Press, autoRepeat=0”
“KeyEvent Press, autoRepeat=0”
“KeyEvent Release, autoRepeat=0”
“KeyEvent Shift Release, autoRepeat=0”
“KeyEvent Ctrl Press, autoRepeat=0”
“KeyEvent Shift Press, autoRepeat=0”
“KeyEvent Press, autoRepeat=0”
“KeyEvent Release, autoRepeat=0”
“KeyEvent Shift Release, autoRepeat=0”
“KeyEvent Ctrl Release, autoRepeat=0”
组合键长按
“KeyEvent Ctrl Press, autoRepeat=0”
“KeyEvent Press, autoRepeat=0”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=1”
“KeyEvent Press, autoRepeat=1”
“KeyEvent Release, autoRepeat=0”
“KeyEvent Ctrl Release, autoRepeat=0”