利用键盘上不使用的SCROLL健,连续按2次,第一次灯亮,第二次灯灭
头文件中
int keyType = 0;
QTimer *keyTimer;
实现
- 绑定信号好槽
#include <windows.h>
keyTimer = new QTimer(this);
connect(keyTimer,SIGNAL(timeout()),this,SLOT(slotKeyTimerOut()));
keyTimer->start(20000);
槽实现
void StatusIcoManager::slotKeyTimerOut()
{
if(keyTimer->isActive())
keyTimer->stop();
if(keyType == 0)
{
keybd_event(VK_SCROLL, 0, KEYEVENTF_EXTENDEDKEY, 0);
keyTimer->start(10);
keyType = 1;
}
else if(keyType == 1)
{
keybd_event(VK_SCROLL, 0, KEYEVENTF_KEYUP, 0);
keyTimer->start(10);
keyType = 2;
}
else if(keyType == 2)
{
keybd_event(VK_SCROLL, 0, KEYEVENTF_EXTENDEDKEY, 0);
keyTimer->start(10);
keyType = 3;
}
else if(keyType == 3)
{
keybd_event(VK_SCROLL, 0, KEYEVENTF_KEYUP, 0);
keyTimer->start(20000);
keyType = 0;
}
}
|