Reputation: 1104
I am writing a program that generates simulated user input, and have created a class to do this. When I try to build it in code::blocks with gcc it throws an error saying "error: 'INPUT' does not name a type". Can someone please explain why I am receiving this error. Below is the header file where the error occurs
#ifndef INPUTSIMULATOR_H
#define INPUTSIMULATOR_H
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#include <Winuser.h>
enum type{KEYBOARD,MOUSE};
enum button{LEFT,RIGHT,MIDDLE};
class inputSimulator
{
public:
inputSimulator(type _inputType);
virtual ~inputSimulator();
int generateKeyEvent (int vk);
int generateMouseButtonDown(button eventType);
int generateMouseButtonUp(button eventType);
int generateMouseMovement(int dy, int dx);
protected:
private:
INPUT input; //error occurs here
type inputType;
};
#endif
Edit: I found another instance of the same issue, but there is no resolution. https://stackoverflow.com/questions/7222529/input-structure-in-simulating-actions-in-winapi
Upvotes: 1
Views: 530
Reputation: 244702
I can't reproduce this problem. When I include windows.h
(which, by the way, you should always include directly, instead of winuser.h
or wingdi.h
), the INPUT
structure is correctly declared and defined just as it should be.
Something is wrong with your Windows headers. The same thing clearly happened to that other person. You're probably both using Code::Blocks or something that provides its own re-implementation of the Windows headers. They either omit the definition of the INPUT
structure or hide it inadvertently.
I recommend downloading and installing the latest version of the Windows SDK, or the Windows 7 SDK, directly from Microsoft. That should solve your problem, unless the hiding of the INPUT
structure is occurring in your own project. Ensure that you're not defining a preprocessor macro with the same name on the command line (or via your IDE's option for doing the same).
Upvotes: 1
Reputation: 25695
Why re-invent the wheel? Use Autoit to automate user input.
You can also use their C++ COM library that helps you easily simulate user interaction.
Upvotes: 0