Ok ... I have a handle to a game window in which inside this game my little character picks up items off the ground and drops them onto himself.
It is done with drag and drop. I left click down drag the item to the character and release the leftclick or let it up.
Using getpixel my program is locating the stuff to pickup of interest. I tried using WM_LBUTTONDOWN, and to a for loop to incriment the x,y coordinates in the SendMessage() function. I was hoping this would simulate a drag and drop. Here is some code for example.
//code for goldpickup hotkey being pressed.
/////Side Top Gold Check
int gmy1 = 160;
for(int gmx1 = 170; gmx1 <= 173; gmx1++)
{
cr = GetPixel(hdcDC,gmx1,gmy1);
if(cr == crGold)
{ gmx1+3;
for(int i = 0; i > 20; i++)
{
SendMessage(hwndDC,WM_LBUTTONDOWN,gmx1,gmy1);
Sleep(500);
gmy1++;
SetPixel(hdcDC,173,gmy1,RedDot);
};
SendMessage(hwndDC,WM_LBUTTONUP,173,gmy1);//Character location
//Drops Gold on Character
};
gmy1 = 160;
SetPixel(hdcDC,gmx1,gmy1,RedDot);
};
This above is what I thought would simulate holding down the mouse and moving it on x,y axis of the games screen I have the window to. However its not working. I added some Sleep() functions thinking maybe messages were being dropped to slow it down a bit, but it still doesnt work. Im not sure if this is the correct way to simulate\automate a drag and drop using code. The mouse icon on the game does not move when this is happening as I am sure its not supposed to. Is there a function I could use to set the cursor to the position I am wanting to automate the moves?
Im guessing here, but I am thinking the code in the game is requiring the mouse icon to be over the gold my character is trying to autonomously pick up, and if thats the case.
Then SendMessage() is sending the messages alright, but without the mouse actually being at those coordinates of sendmessage it means nothing.
Any help would be greatly appreciated.
-Cody