user3422161
user3422161

Reputation: 319

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;
}   

The codes above are simulating to press F5 button, but there are some errors related to declaration. INPUT, INPUT_KEYBOARD, ip were not declared in this scope. How to solve it?

Upvotes: 1

Views: 2065

Answers (2)

paulsm4
paulsm4

Reputation: 121809

You're trying to use "SendInput()", which isn't available in some versions of Windows.

One possibility is to this:

#define WINVER 0x0500
#include <windows.h>
...

This might force Windows to use a specific version ... and might (depending on your specific platform) work exactly like you want :)

Here is the documentation:

Another possibility might be to substitute an OLDER APi, like keybd_event:

To be sure, it would be useful to know your specfic:

  • Platform: Windows 7?

  • Compiler: MSVS 2013?

  • Library: Microsoft-provided Win32 library? "Something else"?

Upvotes: 0

ta.speot.is
ta.speot.is

Reputation: 27214

Without knowing what compiler and platform toolset you're using it's hard to determine what, exactly, is wrong. Reading the fine manual says:

Header Winuser.h (include Windows.h)

Which you're doing.

It also says:

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

Although you'd probably be better off using a recent version of Microsoft Visual Studio and the Windows SDK.

Upvotes: 1

Related Questions