INPUT, INPUT_KEYBOARD, ip没有在这个作用域中声明
INPUT, INPUT_KEYBOARD, ip were not declared in this scope
#include <windows.h>
int main()
{
// This structure will be used to create the keyboard
// input event.
INPUT ip;
// Pause for 10 seconds.
Sleep(1000*10);
// Set up a generic keyboard event.
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0; // hardware scan code for key
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
// Press the "F5" key
ip.ki.wVk = 0x74; // virtual-key code for the "F5" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
// Release the "F5" key
ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
SendInput(1, &ip, sizeof(INPUT));
// Exit normally
return 0;
}
上面的代码是模拟按下F5
按钮,但是在声明方面有一些错误。INPUT, INPUT_KEYBOARD, ip
未在此范围内声明。如何解决?
如果不知道正在使用的编译器和平台工具集,就很难确定究竟是哪里出了问题。阅读精细手册说:
头文件 Winuser.h(包括Windows.h)
你在做什么
它还说:
使用
输入的问题当我尝试使用INPUT结构时,我的编译器告诉我这个结构是未声明的,但是我已经包含了
<windows.h>
。经过一番搜索,我找到了一个解决方案,<winable.h>
也应该包括在内。我不知道为什么,但它有效。MarrySunny
12/6/2011
尽管你最好使用最新版本的Microsoft Visual Studio和Windows SDK。
您正在尝试使用"SendInput()",这在某些版本的Windows中不可用。
一种可能是:
#define WINVER 0x0500
#include <windows.h>
...
这可能会迫使Windows使用特定的版本…并且可能(取决于您的特定平台)完全像您想要的那样工作:)
文档如下:
- http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx
另一种可能是替换旧的APi,如keybd_event:
- http://msdn.microsoft.com/en-us/library/ee504289.aspx
当然,知道你的具体:
平台:Windows 7?
编译器:MSVS 2013?
库:微软提供的Win32库?"别的东西"?
相关文章:
- 未在作用域中声明unordered_map
- 有没有一种方法可以在编译时获得作用域类名
- C++quit()函数中可能存在作用域问题
- 未在此作用域OpenCV3.4中声明cvSaveImage
- 全局作用域中函数指针的赋值
- 在类函数中初始化外部作用域变量
- 不同作用域中的静态变量和全局变量
- 是同一作用域的函数部分中的函数调用
- 未在此作用域中声明的函数和变量 (C++)
- 类作用域的类型别名"using":[何时]方法中的用法可以先于类型别名?
- 将作用域枚举转换为基础类型
- 表达式必须具有完整或无作用域的枚举图
- 在构造函数中输入对象时C++类成员作用域
- 无法让"std::enable_if"适用于无作用域枚举
- 为什么不能直接引用作用域枚举类成员,而不能为无作用域枚举生成类成员?
- 函数未在作用域中声明 / 如何结合使用 header.h、header.cpp 和 main.cpp?
- 错误:表达式必须具有算术、无作用域枚举或带有运算符重载的指针类型
- 如何在C++中访问作用域的变量输出?
- 重载时未在 C++ 的作用域错误中声明
- INPUT, INPUT_KEYBOARD, ip没有在这个作用域中声明