Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Auto clicker thing in C
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
tulio
How do I cheat?
Reputation: 0

Joined: 25 Feb 2007
Posts: 8

PostPosted: Fri Jan 09, 2009 8:53 pm    Post subject: Auto clicker thing in C Reply with quote

So, I have this:

Code:

#define _WIN32_WINNT 0x0501
#include <windows.h>
int main(){
    for(;;){
        Sleep(1);
        while(GetAsyncKeyState(VK_MBUTTON)){
            INPUT ip;
            ip.type=INPUT_MOUSE;
            ip.mi.dwFlags=MOUSEEVENTF_LEFTDOWN;
            SendInput(1,&ip,sizeof(ip));
            ip.mi.dwFlags=MOUSEEVENTF_LEFTUP;
            SendInput(1,&ip,sizeof(ip));
            Sleep(1);
        }
        if(GetAsyncKeyState(VK_END)) break;
    }
        return 0;
}

Compiles and works on windows. But will not work on games because... how can I explain this... GetAsyncKeyState will not anull the MBUTTON (middle mouse button) press. I mean, if you hold mbutton and left click, things will not work. Some say I should use DirectInput in this case, so it would work on hardware level or something, and send left clicks before windows recognizes it as a middle click.
Someone could help me on how to fix that?[/code]
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Fri Jan 09, 2009 9:21 pm    Post subject: Reply with quote

it fails.. cause u double loop.. try this..
Code:

#define _WIN32_WINNT 0x0501
#include <windows.h>
int main()
{
  do
  {
        if(GetAsyncKeyState(VK_MBUTTON))
        {
            INPUT ip;
            ip.type=INPUT_MOUSE;
            ip.mi.dwFlags=MOUSEEVENTF_LEFTDOWN;
            SendInput(1,&ip,sizeof(ip));
            ip.mi.dwFlags=MOUSEEVENTF_LEFTUP;
            SendInput(1,&ip,sizeof(ip));
            Sleep(15);
        }
   }while(!GetAsyncKeyState(VK_END));
   return 0;
}
Back to top
View user's profile Send private message MSN Messenger
tulio
How do I cheat?
Reputation: 0

Joined: 25 Feb 2007
Posts: 8

PostPosted: Fri Jan 09, 2009 9:52 pm    Post subject: Reply with quote

Thank you for helping.
But I couldn't clearly explain my problem.
Compile it with GetAsyncKeyState(VK_SPACE) instead of VK_MBUTTON, then hold SPACE on notepad. It will click really fast, but space will also be insered, where SPACE should only send clicks, not spaces togeter.

From MSDN:
Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application.
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Fri Jan 09, 2009 11:18 pm    Post subject: Reply with quote

Use mouse_event.
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Fri Jan 09, 2009 11:26 pm    Post subject: Reply with quote

_void_ wrote:
Use mouse_event.
Is a wrapper for SendInput. If SendInput doesn't work... what makes you think this will work?
_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Jan 09, 2009 11:33 pm    Post subject: Reply with quote

_void_ wrote:
Use mouse_event.


too bad it's a wrapper for SendInput, and wouldn't work if SendInput does not... oh and

Windows NT/2000/XP: This function has been superseded. Use SendInput instead.



anyway

Quote:
Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon.


also also, SendInput can send everything in one call, like:

(warning: kind of hideous, and yes the formatting is kind of botched, but meh)

Code:
#include <Windows.h>

int main()
{
   char text[]      = "HELLO";
   INPUT ip[10]   = { 0 };
   int   fuck      = 0;

   for(int i = 0; i < 10; i++){      
      if(i & 0x01){ //odd
         ip[i] = ip[i - 1];
         ip[i].ki.dwFlags = KEYEVENTF_KEYUP;
      }
      else{
         ip[i].type    = INPUT_KEYBOARD;
         ip[i].ki.wVk = text[fuck]; fuck++;
      }
   }

   SendInput(10, ip, sizeof(INPUT));
   return 0;   
}
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Sat Jan 10, 2009 2:26 am    Post subject: Reply with quote

tulio wrote:
Thank you for helping.
But I couldn't clearly explain my problem.
Compile it with GetAsyncKeyState(VK_SPACE) instead of VK_MBUTTON, then hold SPACE on notepad. It will click really fast, but space will also be insered, where SPACE should only send clicks, not spaces togeter.

From MSDN:
Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application.

So what you probably want is something like:
Code:
while( GetAsyncKeyState(VK_MBUTTON) & 0x8000 ){ //Will only test the most significant bit
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Sat Jan 10, 2009 5:25 am    Post subject: Reply with quote

tulio wrote:
Thank you for helping.
But I couldn't clearly explain my problem.
Compile it with GetAsyncKeyState(VK_SPACE) instead of VK_MBUTTON, then hold SPACE on notepad. It will click really fast, but space will also be insered, where SPACE should only send clicks, not spaces togeter.

Use a low level keyboard hook to handle & discard the window messages before they are received.

Code:
#include <windows.h>

LRESULT CALLBACK kbProc(int nCode, WPARAM wParam, LPARAM lParam)
{
   if (nCode == HC_ACTION && wParam == WM_KEYDOWN)
   {
      KBDLLHOOKSTRUCT kb = *(KBDLLHOOKSTRUCT *)lParam;

      switch (MapVirtualKey(kb.scanCode, 1))
      {
      case VK_SPACE:
         {
            INPUT ip[2] = { 0 };
            ip[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
            ip[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
            SendInput(2, ip, sizeof(INPUT));

            return 1; // discard the message.
         }
      case VK_END:
         PostQuitMessage(0);
      }
   }
   return CallNextHookEx(NULL, nCode, wParam, lParam);   
}

void init()
{
   HHOOK hHook = SetWindowsHookEx(WH_KEYBOARD_LL, kbProc, GetModuleHandle(NULL), 0);

   MSG Msg;
   while (GetMessage(&Msg, NULL, 0, 0))
   {
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);
   }

   UnhookWindowsHookEx(hHook);
}

int main()
{
   HANDLE hThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)init, 0, 0, 0);
   WaitForSingleObject(hThread, INFINITE);
   return 0;
}
Back to top
View user's profile Send private message
tulio
How do I cheat?
Reputation: 0

Joined: 25 Feb 2007
Posts: 8

PostPosted: Sat Jan 10, 2009 6:34 am    Post subject: Reply with quote

sloppy, your code works just as expected. But I've been trying to use WH_MOUSE_LL instead, since my objective was to use with VK_MBUTTON, but I haven't succeed.
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Sat Jan 10, 2009 8:42 am    Post subject: Reply with quote

Ah whoops.. try with these changes,

Code:
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
   if (nCode == HC_ACTION && wParam == WM_MBUTTONDOWN)
   {
      INPUT ip[2] = { 0 };
      ip[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
      ip[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
      SendInput(2, ip, sizeof(INPUT));

      return 1; // discard the message.
   }
   return CallNextHookEx(NULL, nCode, wParam, lParam);   
}

void init()
{
   HHOOK hHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, GetModuleHandle(NULL), 0);
   ...
}

int main()
{
   DWORD dwThreadId;
   HANDLE hThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)init, 0, 0, &dwThreadId);

   while(!GetAsyncKeyState(VK_END));

   PostThreadMessage(dwThreadId, WM_QUIT, 0, 0);
   WaitForSingleObject(hThread, INFINITE);
   CloseHandle(hThread); // almost forgot ^_-

   return 0;
}
Back to top
View user's profile Send private message
tulio
How do I cheat?
Reputation: 0

Joined: 25 Feb 2007
Posts: 8

PostPosted: Sat Jan 10, 2009 9:51 am    Post subject: Reply with quote

Thank you very much for your time, sloppy.
The mouse version compiles, but doesn't seen to click.
END key kills the process, as expected. But MBUTTON it's not doing no clicks.

I added the following lines to the init function (missing?):
Code:
   MSG Msg;
   while (GetMessage(&Msg, NULL, 0, 0))
   {
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);
   }

   UnhookWindowsHookEx(hHook);

It now clicks, but only once, like a normal click.

-Wall shows the following:

Code:

teste.c: In function 'MouseProc':
teste.c:26: warning: missing braces around initializer //ignore, related to the arrays
teste.c:26: warning: (near initialization for 'ip[0]')
teste.c: In function 'init':
teste.c:38: warning: unused variable 'hHook' // it wasn't showing on the keyboard version
[/quote]
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sat Jan 10, 2009 11:11 am    Post subject: Reply with quote

sponge wrote:
_void_ wrote:
Use mouse_event.
Is a wrapper for SendInput. If SendInput doesn't work... what makes you think this will work?

... What I meant was use mouse_event instead of SendInput for more simplexity.
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Sat Jan 10, 2009 1:28 pm    Post subject: Reply with quote

@tulio
Sorry I should have made it clearer, you only needed to update the first line of init() so I replaced the rest with "..." to indicate it remains the same as the previous code.

I take it you want to send clicks continuously while the middle mouse button is held down?

Code:
#include <windows.h>

bool bMButtonDown;

LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
   if (nCode == HC_ACTION)
   {
      switch (wParam)
      {
      case WM_MBUTTONDOWN:
      case WM_MBUTTONUP:
         bMButtonDown = (wParam == WM_MBUTTONDOWN) ? true : false;
         return 1;
      }
   }
   return CallNextHookEx(NULL, nCode, wParam, lParam);   
}

void init()
{
   HHOOK hHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, GetModuleHandle(NULL), 0);

   MSG Msg;
   while (GetMessage(&Msg, NULL, 0, 0))
   {
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);
   }

   UnhookWindowsHookEx(hHook);
}

int main()
{
   DWORD dwThreadId;
   HANDLE hThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)init, 0, 0, &dwThreadId);

   while(true)
   {
      if (bMButtonDown)
      {
         INPUT ip[2] = { 0 };
         ip[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
         ip[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
         SendInput(2, ip, sizeof(INPUT));

         Sleep(100);
      }
      if (GetAsyncKeyState(VK_END))
         break;
   }

   PostThreadMessage(dwThreadId, WM_QUIT, 0, 0);
   WaitForSingleObject(hThread, INFINITE);
   CloseHandle(hThread);

   return 0;
}
Back to top
View user's profile Send private message
tulio
How do I cheat?
Reputation: 0

Joined: 25 Feb 2007
Posts: 8

PostPosted: Thu Jan 22, 2009 7:09 pm    Post subject: Reply with quote

Hi, sloppy. I hadn't had time to thank you.
To thank this community. Sorry for bumping the topic tho...
I'm not able to compile the code, but I'm guessing you did that on purpose so I could learn more. I'll fix that, :PP. Thank you very much, sloppy, :PP.
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Thu Jan 22, 2009 7:49 pm    Post subject: Reply with quote

You're welcome tulio. The code above should work as is.. though if you have any problems with it, post the errors so we can help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites