[英]QT/C++: Getting LASTINPUTINFO to work
嗨,我正在通過QT學習C ++,我正在努力使LASTINPUTINFO工作。 下面是我制作的代碼,以查看其工作原理,但似乎只返回一個值,並且無論何時輸入任何內容都不會改變。
願意解釋我做錯了什么嗎? 也許可以提供一個可行的示例,以便我掌握。
我正在嘗試在Windows 10 Pro 64位上運行它。
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <Windows.h>
#include <unistd.h>
using namespace std;
test()
{
LASTINPUTINFO lastii;
lastii.cbSize = sizeof(LASTINPUTINFO);
return lastii.dwTime;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
while (true) {
qDebug() << test();
sleep(1);
}
return a.exec();
}
示例輸出在這里。
138899896
138899896
138899896
138899896
138899896
138899896
138899896
固定代碼供參考。 多虧了安德斯(Anders)。
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <Windows.h>
#include <unistd.h>
#include <iostream>
using namespace std;
test()
{
LASTINPUTINFO lastii;
lastii.cbSize = sizeof(LASTINPUTINFO);
GetLastInputInfo(&lastii);
return (GetTickCount() - lastii.dwTime) / 1000;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
while (true) {
cout<<test()<<"\n";
sleep(1);
}
return a.exec();
}
LASTINPUTINFO
不是類,它是一個簡單的C結構。 您實際上必須調用一個函數來填充它:
DWORD test() {
LASTINPUTINFO lastii;
lastii.cbSize = sizeof(LASTINPUTINFO);
GetLastInputInfo(&lastii);
return lastii.dwTime;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.