-
INPUT error
I have this code that gets the color of 4 pixels off the screen and checks them to see if they are white, but I am getting an error at INPUT saying that it is an unknown identifier. Any help?
Code:
#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HDC hdcScrn;
hdcScrn = CreateDC((LPCWSTR)"DISPLAY", 0, 0, 0); //Capture the screen
COLORREF Col1,Col2,Col3,Col4; //Colors
POINT LP, RP, UP, DP;
LP.x = 374;LP.y = 391;
RP.x = 627;RP.y = 387;
UP.x = 533;UP.y = 362;
DP.x = 467;DP.y = 415;
//Define the input keys
INPUT Left, Right, Up, Down;
Left.type = INPUT_KEYBOARD;
Right.type = INPUT_KEYBOARD;
Up.type = INPUT_KEYBOARD;
Down.type = INPUT_KEYBOARD;
Left.ki.wVk = VK_LEFT;
Right.ki.wVk = VK_RIGHT;
Up.ki.wVk = VK_UP;
Down.ki.wVk = VK_DOWN;
while (true)
{
//SetActiveWindow(hWnd);
Col1 = GetPixel(hdcScrn, LP.x, LP.y);
Col2 = GetPixel(hdcScrn, RP.x, RP.y);
Col3 = GetPixel(hdcScrn, UP.x, UP.y);
Col4 = GetPixel(hdcScrn, DP.x, DP.y);
if (Col1 == 16777215)//left
{
SendInput(1, &Left, sizeof(INPUT));
}
if (Col2 == 16777215)//right
{
SendInput(1, &Right, sizeof(INPUT));
}
if (Col3 == 16777215)//up
{
SendInput(1, &Up, sizeof(INPUT));
}
if (Col4 == 16777215)//down
{
SendInput(1, &Down, sizeof(INPUT));
}
}
DeleteDC(hdcScrn); // deletes the handle
return 0;
}
Edit: Had the POINT stuff screwed up, fixed now.
-
Where did you get that code from? INPUT is a type that has to be defined somewhere. It looks like you think it is defined in windows.h (or in a header you include in stdafx.h), but apparently it is not.
-
Oh... I read somewhere that it was included in windows.h. I'll do some more reading on MSDN and see if I can figure it out.
http://msdn2.microsoft.com/en-us/library/ms646270.aspx
It says it is defined in winuser.h and to include windows.h
-
Code:
typedef struct tagINPUT {
DWORD type;
union
{
MOUSEINPUT mi;
KEYBDINPUT ki;
HARDWAREINPUT hi;
};
} INPUT, *PINPUT, FAR* LPINPUT;
Include winable.h.
-
Ok, I did that. It got rid of all the errors =) Thank you very much.
But now I get these errors when linking:
error LNK2019: unresolved external symbol __imp__DeleteDC@4 referenced in function _wmain
error LNK2019: unresolved external symbol _SendInput@12 referenced in function _wmain
error LNK2019: unresolved external symbol __imp__GetPixel@12 referenced in function _wmain
error LNK2019: unresolved external symbol __imp__CreateDCW@16 referenced in function _wmain
-
You're missing a .lib library that you need to include in your project. I can't tell you off the top of my head which it is. At least, that is the most common way to get that error. What you can be sure of is that the compiler knows that those functions exist. It just can't find them.
-
The MSDN site says they are in gdi32.lib. I searched my computer for it and found 2 copies and then checked what libraries are included in VC++, and the folders that contain them are included. So I am out of ideas.
-
I've never used VC, but I'd assume that you have to link to that library thru linker options, no?
For Dev, I do;
"C:\Dev-Cpp\lib\libgdi32.a"
More than likely, someone will come on by and toss you the bone you need....
-
Yes, you need to go to the Project Properties/Settings and under Linker put gdi32.lib as an additional dependency.
-
Awesome! Compiles now. I had to add gdi32.lib and user32.lib as addictional dependencies. Thanks for the awesome and fast help everyone.