 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Wed Jan 02, 2008 9:19 am Post subject: [C] Using Sendinput() .-*~.Still Unresolveed.~*-. |
|
|
I am trying to create a very simple auto clicker, purely for learning purposes. Before anyone says, I know about x0r's simple auto clicker. I don't want it to be able to bypass GG, or send input to another program, or have editable speed or anything, although I may advance on these specification later. I just want to create a simple auto clicker, to click the mouse at it's current position, maybe with a hot key at most.
I have searched and found that the best way to do this is to this is using Sendinput(), although keybd_event() and mouse_event() are a lot easier, I find it would be a bad habit to get into using them, as they only work on Windows 98 down. I have searched the site and web, and found nothing which explains it to me in a way I can understand, at least.
I was thinking of just having 1 function, I don't know about threads or timers yet, which will be on a loop and click the mouse. All it needs is an exit, so maybe use a while loop, and to check if a key is pressed, to change a value of a variable, and exit from the loop. So in pseudo:
| Code: | If variable is 0,
If hotkey is pressed,
Change value of variable to 1,
Else loop
If variable is 1,
Click the mouse,
If hotkey is pressed,
Change the value of variable to 0,
Return 0,
Else loop |
I may optimize later. But for now, the simplest possible please.
If I cannot do this because it is still too complicated, I will just give up hope! For now...
P.S. I have only come back to CEF briefly.
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Last edited by --Pillboi-- on Wed Jan 02, 2008 1:15 pm; edited 3 times in total |
|
| Back to top |
|
 |
Cx Master Cheater
Reputation: 0
Joined: 27 Jul 2007 Posts: 367
|
Posted: Wed Jan 02, 2008 10:02 am Post subject: |
|
|
Would you do it all in a single thread?
_________________
armed with this small butterfly net
i will face the world alone
& never be lonely. |
|
| Back to top |
|
 |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Wed Jan 02, 2008 10:09 am Post subject: |
|
|
That's what I'm saying. Single thread, single function. Unless there is an easier way than I have suggested. I could use threads if it is better/just as easy. Also, please, I really don't want to start a discussion on the best way to make an AC!
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair. |
|
| Back to top |
|
 |
Cx Master Cheater
Reputation: 0
Joined: 27 Jul 2007 Posts: 367
|
Posted: Wed Jan 02, 2008 10:22 am Post subject: |
|
|
So, like, all in one loop?
Keep the delays/sleeps to a MINIMUM, or else the GetAsyncKeyState code may not be read when you do the hotkey!
Kinda lame, but:
| Code: | BOOL bAC = 0; // AC boolean.
DWORD DelayVal = 0; // Delay between clicks (note that it's in a thread with other stuff, so the delay will be longer than this number).
for(;;) // Endless loop (unless broken).
{
if(GetAsyncKeyState(VK_F12)) // GetAsyncKeyState hotkey.
{
bAC = !bAC // Toggles the bool.
Sleep(300); // Sleep to make sure that it doesnt toggle more than once.
}
if (bAC == 1) // If bool is TRUE,
{
/////////////// // Whatever method you use to click.
Sleep(DelayVal); // Delay.
}
Sleep(50); // So you don't make your computer go crazy.
} |
What API do you want to use to click?
_________________
armed with this small butterfly net
i will face the world alone
& never be lonely. |
|
| Back to top |
|
 |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Wed Jan 02, 2008 10:50 am Post subject: |
|
|
Ok, thankyou so much. I don't really know about BOOL. But I get the idea, and know what a boolean value is. I would like to use sendinput(), as I have heard it is the most efficient way. Can you please explain how I would go about doing this. So is this the sort of thing? It's just your code edited and completed, the tiniest bit.
| Code: | #include <stdio.h>
#include <stdlib.h> //Are these the right headers?
int main(int argc, char *argv[])
{
BOOL bAC = 0; // AC boolean.
DWORD DelayVal = 0; // Delay between clicks (note that it's in a thread with other stuff, so the delay will be longer than this number).
scanf("%d", &DelayVal); //How would I make some sort of box for this?
for(;;) // Endless loop (unless broken).
... |
If I wanted to put this into a windows application from a project, how would I go about inserting it into this? (It's what the compiler gives)
| Code: | #include <windows.h>
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|
I'm truly sorry for the very nooby question. Or How would I go about doing it with GTK+?
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair. |
|
| Back to top |
|
 |
Cx Master Cheater
Reputation: 0
Joined: 27 Jul 2007 Posts: 367
|
|
| Back to top |
|
 |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Wed Jan 02, 2008 1:45 pm Post subject: |
|
|
Ok, thank you, again. I'm reading a tutorial for it now!.
I've already read up on sendinput on msdn, unfortunately, it doesn't say, or I can't find, how to actually use it. Is it meant to be used like so?
| Code: | UINT SendInput(
UINT 1,
LPINPUT 0x01, //or VK_LBUTTON
int cbSize //I don't even know where to begin with this.
); |
OR
| Code: | | UINT SendInput(LPINPUT 0x01); //or VK_LBUTTON |
I am using http://www.kbdedit.com/manual/low_level_vk_list.html for the virtual key code. Sorry it took so long to reply, CE has died.
Edit: Looking at some source code, I have found that you use it like this:
| Code: | SendInput(2, MOUSEEVENTF_LEFTDOWN, sizeof(input));
SendInput(2, MOUSEEVENTF_LEFTUP, sizeof(input)); |
Or can put all the mouse buttons into an array like this:
| Code: |
int button[1]
...
button[0].type= input[1].type= INPUT_MOUSE;
button[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
button[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(2, input, sizeof(input)); |
Taken from slovach version of x0r's simple AC.
But could use it like this:
| Code: |
int button[1]
...
button[0].type= input[1].type= INPUT_MOUSE;
button[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
button[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
for(input[]==0;input++)
SendInput(2, input, sizeof(input));
for(input[]==1;input--)
SendInput(2, input, sizeof(input)); |
Or even simply:
| Code: |
int button[1]
...
button[0].type= input[1].type= INPUT_MOUSE;
button[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
button[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(2, input[0], sizeof(input));
SendInput(2, input[1], sizeof(input)); |
Anyway, that's lots of code for now. xD
Edit 2: I am having a few problems compiling:
Fixed problems
1st:
I sorted this out, as apparently BOOL is not C. So made it
2nd: | Code: | | DWORD DelayVal = 0; |
Again, apparently not C, but I always though it was. Anyhow, I fixed it: | Code: | | unsigned long DelayVal = 0; |
3rd:
It is not a boolean value any more. Fixed by using if commands: | Code: | | if(bAC==0) { bAC = 1; } if(bAC==1) { bAC = 0; } |
Unfixed problems Tried but failed!
1st: | Code: | | if(GetAsyncKeyState(VK_F12)) |
Compiler says that VK_F12 is undeclared.
2nd: | Code: | SendInput(2, MOUSEEVENTF_LEFTDOWN, sizeof(input));
SendInput(2, MOUSEEVENTF_LEFTUP, sizeof(input)); |
Compiler says MOUSEEVENTF_LEFTUP/DOWN and input is undeclared.
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair. |
|
| Back to top |
|
 |
Cx Master Cheater
Reputation: 0
Joined: 27 Jul 2007 Posts: 367
|
Posted: Wed Jan 02, 2008 2:05 pm Post subject: |
|
|
VK_F12 == 0x7B.
So you can just use this, if you want:
| Code: | | if(GetAsyncKeyState(0x7B)) |
And SendInput might be confusing. MSDN says you it requires a structure (INPUT structure), and that code you posted would get the size of the structure...
_________________
armed with this small butterfly net
i will face the world alone
& never be lonely. |
|
| Back to top |
|
 |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Wed Jan 02, 2008 2:50 pm Post subject: |
|
|
I'm not using a structure, I'm using an array, and not getting that error anymore. But getting other errors. Even after using structures and it still won't work, so I've reverted back to arrays. I'm PMing you the source.
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair. |
|
| Back to top |
|
 |
Cx Master Cheater
Reputation: 0
Joined: 27 Jul 2007 Posts: 367
|
Posted: Wed Jan 02, 2008 3:10 pm Post subject: |
|
|
| Code: | if(bAC==0)
{
bAC = 1; // Toggles the bool.
}
if(bAC==1)
{
bAC = 0;
} |
There's the problem. If the bAC == 0, it will switch it to 1. Then in the next if statement, since bAC now == 1, it will switch back to 0.
Make it an else.
| Code: | if(bAC==0)
bAC = 1;
else
bAC = 0; |
And I'm not sure if SendInput is being used correctly.
Can it compile?
_________________
armed with this small butterfly net
i will face the world alone
& never be lonely. |
|
| Back to top |
|
 |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Wed Jan 02, 2008 4:45 pm Post subject: |
|
|
Thanks, my compiler didn't pick up on that, and I suppose why would it, when it's a logical error. The compiler still didn't compile it, and your right, it is the SendInput that is the problem.
Errors:
| Code: | request for member 'type' in something not a structure or union.
'INPUT_MOUSE' undeclared
request for member 'mi' in something not a structure or union. |
Before anyone asks, yes I did get the whole SendInput bit from x0r's AC. Lol.
This really isn't almost any of my work. Although, I suppose it doesn't matter as long as I don't take advantage of the code. I am still learning from it. I think~
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Wed Jan 02, 2008 5:30 pm Post subject: |
|
|
i found this on my computer.. someone posted it here i remember, but i cant remember who
anyways its an example of how to use SendInput.
| Code: | void Send(unsigned short vk)
{
INPUT aInput;
memset(&aInput,0,sizeof(INPUT));
aInput.type = INPUT_KEYBOARD;
aInput.ki.wVk = vk;
aInput.ki.dwFlags = 0;
SendInput(1,&aInput,sizeof(INPUT));
aInput.type = INPUT_KEYBOARD;
aInput.ki.wVk = vk;
aInput.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1,&aInput,sizeof(INPUT));
} |
_________________
|
|
| Back to top |
|
 |
--Pillboi-- Grandmaster Cheater Supreme
Reputation: 0
Joined: 06 Mar 2007 Posts: 1383 Location: I don't understand the question. Is this a 1 to 10 thing?
|
Posted: Wed Jan 02, 2008 5:52 pm Post subject: |
|
|
Thank you lurc, helped a lot.
I have deleted the old code and have started to rewrite the whole thing myself, using what I learnt here today. It probably won't work, but it's worth a try. I'll post it later maybe.
_________________
Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Wed Jan 02, 2008 9:46 pm Post subject: |
|
|
i think (not sure) that the first sendinput isnt supposed to be
.dwFlags = 0;
its supposed to be
.dwFlags = KEYEVENTF_KEYDOWN;
_________________
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Wed Jan 02, 2008 10:23 pm Post subject: |
|
|
KEYEVENTF_KEYDOWN == 0
but it's a good idea to use KEYEVENTF_KEYDOWN because it could change.
_________________
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|