c++ - INPUT、INPUT_KEYBOARD、ip 未在此范围内声明

标签 c++ windows winapi

#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 未在此范围内声明。 如何解决?

最佳答案

在不知道您使用的编译器和平台工具集的情况下,很难确定到底哪里出了问题。 Reading the fine manual说:

Header Winuser.h (include Windows.h)

你在做什么。

它还说:

A problem with INPUT using

When I try to use the INPUT structure, my compiler tells me this structure is undeclared, but I have included <windows.h>. After some searching, I find a solution, the <winable.h> should also be included. I don't know why, but it works.

MarrySunny
12/6/2011

尽管您最好使用最新版本的 Microsoft Visual Studio 和 Windows SDK。

关于c++ - INPUT、INPUT_KEYBOARD、ip 未在此范围内声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22432889/

相关文章:

ruby-on-rails - Windows 上的 Ruby on Rails 开发

windows - 如何消除脚本 block 中的重复代码?

c++ - 在 KMDF 驱动程序中包含 fstream.h 后出现链接器错误

c - 使用 GWL_WNDPROC 子类化 richedit 的问题

c++ - 使用 DllMain 函数创建 Windows 共享库 (MinGW + CMake)

c++ - Makefile 模式规则差异

c++ - cmake find_library 和 CMAKE_FIND_ROOT_PATH

c++ - 在 C++ 中创建一个列表来保存对象

c - WinAPI 组合框问题 - 按案例跳过

c++ - 如何从 Python 使用 Microsoft MIP SDK?