1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
/********************************************************************************/
/* This is a simple dog program that can point-and-click and send what I will */
/* call 'Bark streams' to another program -- the active window. That is, it */
/* will output text to other programs and move around a p-a-c game's interface. */
/* I am hoping to add the possibility of colour detection, and at some point */
/* a very simple decision tree. */
/********************************************************************************/
#define (_WIN32_WINNT >= 0x0404)
#include <windows.h>
// Defining SendInput() as for whatever reason it cannot work on it's own.
HRESULT __stdcall SendInput(
BSTR Command,
VARIANT_BOOL Execute
);
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
// The Window Procedure -- this handles messages.
char szClassName[]="Dog"; /* The class name of the Window.
This is pretty pointless as we don't have a Window
but it can stay anyway.*/
class dog { /* The dog's class. I would use a simpler method but for some reason
I have taken a liking to classes... */
public:
void movemnt( ); // Motion (SendInput)
void brkout ( ); // Dog bark output
};
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
LPSTR lpszArgument, int nFunsterStil) { // There will be no window as we will not define one :P
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); /* So that we do not
eat too much processor time, we will make sure we only use non-allocated processor time. */
do {
dog dg;
dg.movemnt();
dg.brkout ();
Sleep(1000); /* To save a little more on processor time, we will sleep for one second after every loop.
This also helps in that we will not move around and bark too often :P */
} while (true); /* Never ending loop -- we only want this process to close if it is closed by the user.
As we have no window, they can only close from Task Manager anyway, so it doesn't matter.
But we still want to run the loop indefinately. */
return 0; // We completed with no errors.
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0); // When the user attempts to exit, we will send the process to the exit queue.
default:
return DefWindowProc(hwnd, msg, lp, wp); /* For messages that we do not handle,
we can return the default window procedure. */
} /* There are no other message cases because we don't have any expected messages --
we just want WM_DESTROY. So we can leave the rest to DefWindowProc. */
return 0; // In the case that we don't get any messages, we can just return 0.
}
// The following is the only function which does not work.
void dog::movemnt() { // The dog will move around and click.
int x, y;
double fScreenWidth = ::GetSystemMetrics(SM_CXSCREEN)-1;
double fScreenHeight = ::GetSystemMetrics(SM_CYSCREEN)-1;
double fx = x*(65535.0f/fScreenWidth);
double fy = y*(65535.0f/fScreenHeight);
INPUT Input = {0};
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
Input.mi.dx = fx;
Input.mi.dy = fy;
::SendInput(1,&Input,sizeof(INPUT));
INPUT Input={0};
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
::SendInput(1,&Input,sizeof(INPUT));
::ZeroMemory(&Input,sizeof(INPUT));
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
::SendInput(1,&Input,sizeof(INPUT));
}
void dog::brkout() { // The dog will output "woof woof" or similar.
// This remains unwritten as of yet.
}
|