QT/C++: Getting LASTINPUTINFO to work
QT/C++: Getting LASTINPUTINFO to work
嗨,我正在
通过QT学习C++,我正在尝试让LASTINPUTINFO工作。下面是我为了解它的工作原理而编写的代码,但它似乎只返回一个值,并且在我进行任何输入时都不会更改。
想解释我做错了什么吗?也许提供一个工作示例,以便我掌握。
我正在尝试在 Windows 10 专业版 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
固定代码以供参考。感谢安德斯。
#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;
}
相关文章:
- "error: no matching function for call to"构造函数错误
- 调用专用模板时出错"no matching function for call to [...]"
- C++ Singleton - Prevent ::instance() to variable
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- Visual Studio Code "undefined reference to `WinMain@16'"
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 如何解决"invalid conversion from 'char' to 'const char*'"
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- Python str to C++ to Python str
- 为什么创建友元类的实例会导致"undefined reference to"错误?
- System.InvalidCastException - SQL to C++ - safe_cast<float>
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- "no matching function for call to 'Vector::Vector'"错误
- vector<vector<double>> to mxArray using memcpy
- Tensorflow c++ api undefined reference to 'tflite::D efaultErrorReporter()'
- 当覆盖存在时调用基本虚拟"binded to object"函数
- OpenGL VBO Indexing ( How to compute Index Array)
- 为什么我会" void value not ignored as it ought to be"?
- QT/C++: Getting LASTINPUTINFO to work