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 


[C] Using Sendinput() .-*~.Still Unresolveed.~*-.
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Wed Jan 02, 2008 10:28 pm    Post subject: Reply with quote

heres an example dll.

hope it helps

F11 to enable, F12 to disable.

Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

BOOL bExit = FALSE;

DWORD WINAPI Click()
{
   while ( !bExit )
   {
      if ( GetAsyncKeyState( VK_F11 )&1 )
      {
         for ( ; ; )
         {
            if ( GetAsyncKeyState( VK_F12 )&1 )
            {
               break;
            }

            INPUT aInput;

            memset(&aInput, 0, sizeof(INPUT));

            aInput.type = INPUT_MOUSE;
            aInput.mi.mouseData = 0;
            aInput.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
            aInput.mi.dwExtraInfo = 0;
            aInput.mi.time = 0;

            SendInput(1, &aInput, sizeof(INPUT));

            aInput.type = INPUT_MOUSE;
            aInput.mi.mouseData = 0;
            aInput.mi.dwFlags = MOUSEEVENTF_LEFTUP;
            aInput.mi.dwExtraInfo = 0;
            aInput.mi.time = 0;

            SendInput(1, &aInput, sizeof(INPUT));
            Sleep ( 1000 ); //Change this for click speed.
         }
      }
      Sleep( 100 );
   }
   return 0;
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwMsg, LPVOID lpReserved)
{
   switch( dwMsg )
   {
   case DLL_PROCESS_ATTACH:
      DisableThreadLibraryCalls( hModule );
      CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)Click, NULL, 0, 0 );
      return TRUE;
   case DLL_PROCESS_DETACH:
      bExit = TRUE;
      return TRUE;
   }
   return TRUE;
}


tested it on minesweeper. all good.

edit: oh i c appalsap, i shoulda checked what value it was. ok ill keep that in mind

_________________
Back to top
View user's profile Send private 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?

PostPosted: Thu Jan 03, 2008 8:47 am    Post subject: Reply with quote

That's pretty much exactly what I meant! Except that mines going to be an executable. Erm. I'm having problems with Send Input still. This is what I wrote:
Code:
#include <stdio.h>
#include <windows.h>

int main(int argc, char *argv[])
{
  int bAC = 0;            // AC boolean.
  unsigned long DelayVal = 20;         // Delay between clicks (note that it's in a thread with other stuff, so the delay will be longer than this number).     

printf("What would you like the delay between clicks to be?\n");
printf("The recommended value is between 10 and 100:");
scanf("%d", &DelayVal); //How would I make some sort of box for this?

for(;;)               // Endless loop (unless broken).
{
   if(GetAsyncKeyState(0x7B))   // GetAsyncKeyState hotkey.
   {
      if(bAC==0)
      {
        bAC = !bAC;      // Toggles the bool. I found out that this works with an integer variable like it was a BOOL.
      } else {     
      bAC = 0;
      }
      Sleep(300);      // Sleep to make sure that it doesnt toggle more than once.
   }

   if (bAC == 1)         // If bool is TRUE,
   {
void LeftClick();
   }
   Sleep(50);         // So you don't make your computer go crazy.
}


}
void LeftClick() {

  int DelayVal = 20;
  unsigned long Input;
  // left down
  ZeroMemory(&Input,sizeof(Input));
  Input.type = INPUT_MOUSE;
  Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
  SendInput(1,&Input,sizeof(Input));

  // left up
  ZeroMemory(&Input,sizeof(Input));
  Input.type = INPUT_MOUSE;
  Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
  SendInput(1,&Input,sizeof(Input));
 
  //Delay
  Sleep(DelayVal);
}

void RightClick() {     
     
  int DelayVal = 20;
  unsigned long Input;
  // left down
  ZeroMemory(&Input,sizeof(Input));
  Input.type = INPUT_MOUSE;
  Input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
  SendInput(1,&Input,sizeof(Input));

  // left up
  ZeroMemory(&Input,sizeof(Input));
  Input.type = INPUT_MOUSE;
  Input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
  SendInput(1,&Input,sizeof(Input));
 
  //Delay
  Sleep(DelayVal);
}

_________________

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
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Thu Jan 03, 2008 11:05 am    Post subject: Reply with quote

what are the problems?

and btw, u forgot to return 0; at the end of ur int main.
and cant you use "bool" instead of "BOOL" or does it still not work in your compiler...


Edit: ConsoleApp working:

Code:
#include <windows.h>
#include <stdio.h>

bool bAC = false;
unsigned long DelayVal;

int main(int argc, char *argv[])
{
   printf("Please Enter a Clicking Speed.\n");
   scanf("%d", &DelayVal);

   if ( DelayVal != NULL )
      bAC = true;

   printf("Press F11 to start clicking, and F12 to stop\n\n");

   while ( bAC )
   {
      if ( GetAsyncKeyState( 0x7A ) )
      {
         for ( ; ; )
         {
            if ( GetAsyncKeyState( 0x7B ) )
            {
               break;
            }

            INPUT aInput;

            memset(&aInput, 0, sizeof(INPUT));

            aInput.type = INPUT_MOUSE;
            aInput.mi.mouseData = 0;
            aInput.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
            aInput.mi.dwExtraInfo = 0;
            aInput.mi.time = 0;

            SendInput(1, &aInput, sizeof(INPUT));

            aInput.type = INPUT_MOUSE;
            aInput.mi.mouseData = 0;
            aInput.mi.dwFlags = MOUSEEVENTF_LEFTUP;
            aInput.mi.dwExtraInfo = 0;
            aInput.mi.time = 0;

            SendInput(1, &aInput, sizeof(INPUT));
            Sleep( DelayVal );
         }
      }
      Sleep( 100 );
   }
   return 0;
}


edit 2: if u need to change "bool" to "int" then make it

int bAC = 1;

if ( DelayVal != NULL )
bAC = 0;

while ( bAC == 0 )

_________________
Back to top
View user's profile Send private 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?

PostPosted: Thu Jan 03, 2008 11:40 am    Post subject: Reply with quote

Oh yeah, your right I did forget to return 0. I also forgot to close the main function I think. That could be causing some problems... Either bool doesn't work, but it doesn't matter, because int works just as well. With both int and bool variables, the opposite of 1 is 0, and vice versa. Thanks for making that example for me. I don't see why yours should work and not mine. I haven't tried compiling your yet so I'll tell you what happens when I try to. Is the "if ( DelayVal != NULL ) " just an error checker, in case the user doesn't enter a value before pressing enter? But in that case, it should return 1 if they haven't entered a value. "while bAC == 0", would mean to click when the toggle key is off, it just makes more sense the other way, same with "int bAC = 1;", that would mean as soon as you open it and enter a speed, it would start clicking. My compiler says with mine, that INPUT is not declared, and says that INPUT_MOUSE and mi and a few other things are also not declared. Also, in your example, you don't need: "aInput.mi.dwExtraInfo = 0; / aInput.mi.time = 0;", as they are automatically null. That's why I didn't put them in. Also, with yours, when they turn the AC off, wouldn't it ask them what speed they wanted to click at again?

Edit: When trying to compile yours, unsurprisingly, it tells me that there is a syntax error before bAC, which is bool. It tells me, again not surprisingly, that false is undeclared. And also that, still on line 4, data definition has no type or storage class. Then on line 12, it tells me that comparison between pointers and integers is an error, and, on the next line, true is undeclared; not surprising, again! On line 28 it says that INPUT is undeclared, and that there is a syntax error before aInput. For line 30, it says that aInput is undeclared. And on line 32, INPUT_MOUSE is undeclared. I just downloaded this compiler, and it's still in beta, so maybe that's the problem, but I doubt it. It's Dev-C++ V. 4.9.9.2. Thanks again for writing that code for me, it's unfortunate that it didn't work. Maybe, try compiling my code on your compiler.

_________________

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
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Thu Jan 03, 2008 11:59 am    Post subject: Reply with quote

Yea your using Dev-Cpp, thats your problem.

im using Visual Studio 2008 Proffessional

heres a way to change your click speed:

code works and everything

and ill try compiling yours with my IDE

Code:
#include <windows.h>
#include <stdio.h>

bool bAC = false;
unsigned long DelayVal;

void ChangeSpeed()
{
   printf("Please Enter a Clicking Speed. (In Milliseconds)\n");
   scanf("%d", &DelayVal);
   printf("Click Speed Set to %d Second(s)", DelayVal / 1000);
   printf("\n\nPress F11 to start clicking, F12 to stop, and C to change the Click Speed\n\n");
   bAC = true;
}

int main(int argc, char *argv[])
{
   ChangeSpeed();
   while ( bAC )
   {
      if ( GetAsyncKeyState( 0x7A ) )
      {
         printf("Clicking Starting in 2 Seconds\n\n");
         Sleep( 2000 );

         for ( ; ; )
         {
            if ( GetAsyncKeyState( 0x7B ) )
            {
               printf("Clicking Stopped\n\n");
               break;
            }

            INPUT aInput;

            memset(&aInput, 0, sizeof(INPUT));

            aInput.type = INPUT_MOUSE;
            aInput.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;

            SendInput(1, &aInput, sizeof(INPUT));

            aInput.type = INPUT_MOUSE; 
            aInput.mi.dwFlags = MOUSEEVENTF_LEFTUP;

            SendInput(1, &aInput, sizeof(INPUT));
            Sleep( DelayVal );
         }
      }
      if ( GetAsyncKeyState( 0x43 ) )
      {
         bAC = false;
         ChangeSpeed();
      }
      
      Sleep( 100 );
   }
   return 0;
}


Edit: Your code would compile fine on my IDE as long as i stated INPUT Input.

_________________
Back to top
View user's profile Send private 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?

PostPosted: Thu Jan 03, 2008 12:11 pm    Post subject: Reply with quote

How many links did you need to download to get VS for free? lol
Or did you buy it? Or use a keygen (I don't know if there are any)?
Oh I see, that's a nice idea, what would be better, if you could have that option, and you could press + and - to make the AC a bit faster or slower (like it MZBot), without pausing the AC, or having to put the screen focus on the application. Also, C isn't a really a good hotkey, in case you need to write something with C in, when the AC is turned off. When you break; won't it just jump out of the while statement and end the program? Other than that, it is a very nicely programmed, only doing what it needs to and one time, it's very efficient. For example, when waiting for the hotkey to be pressed, it doesn't go through the whole thing, just without clicking, before checking again. Thanks for trying to compile mine for me.

Edit: Oh, ok, thanks. Can you please upload it. Eh. Anyway, how did you get Visual Studio?

_________________

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
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Thu Jan 03, 2008 12:28 pm    Post subject: Reply with quote

yea i know C isnt a good hotkey, you can use whatever other hotkey u want but i was just showing u an example.

if u wanted to add + and - keys you can use RegisterHotKey so u dont have to have focus to the application. that way u dont have to pause the AC either. and when i break i only break from the for loop. if i wanted to break out of the while loop id change bAC to false

got VS 2008 from downloading 60+ rapidshare links of 50 MB files.. Confused

i think i can find less now. that was back when i had a RS account Sad

ill send you some links via PM since CEF doesnt allow illigal programs.

btw, i changed ur coding just by a bit, had to rename Input to aInput, and then i also had to move DelayVal and bAC out of int main so its declared throughout the whole project instead of losing it in seperate functions Smile

compiled exe's, sources are posted above:



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.


The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.


_________________
Back to top
View user's profile Send private 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?

PostPosted: Thu Jan 03, 2008 1:00 pm    Post subject: Reply with quote

Thanks a lot, both for the warez links, and the compiled programs. You've helped me so much. I'll try them both now! Good point, I completely forgot to move them when I made the two extra functions. Thanks. Downloading...

Edit: "This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem."
This happens for both .exe's. Do you know what's the problem?

_________________

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
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Thu Jan 03, 2008 1:09 pm    Post subject: Reply with quote

i think u need .NET Framework seeing as they were compiled with Microsoft Visual Studio

http://www.microsoft.com/downloads/details.aspx?FamilyId=0856EACB-4362-4B0D-8EDD-AAB15C5E04F5&displaylang=en

_________________
Back to top
View user's profile Send private message
mOnSoOn
Expert Cheater
Reputation: 0

Joined: 05 Jul 2007
Posts: 203

PostPosted: Thu Jan 03, 2008 2:18 pm    Post subject: Reply with quote

noz3001 ftw. It's not for the mouse but.. It may help maybe..
Here's his code (I remember that I learned alot when I wanted to use SendInput):
Code:
#define _WIN32_WINNT 0×0500 // needed in old compilers
#include “windows.h”

void SendKey(BYTE vKey)
{
INPUT Input;
ZeroMemory(&Input, sizeof(Input)); // Sets all members to 0
Input.type = INPUT_KEYBOARD; // keybd_event
Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
Input.ki.wVk = vKey; // Virtual Key
SendInput(1, &Input, sizeof(INPUT));
}

int main()
{
HWND Notepad = FindWindow(”Notepad”, 0);
if(!Notepad) return 0;

SetForegroundWindow(Notepad);
Sleep(500);

SendKey((UCHAR)VkKeyScan(’h'));
SendKey((UCHAR)VkKeyScan(’i'));
SendKey((UCHAR)VkKeyScan(’y'));
SendKey((UCHAR)VkKeyScan(’a'));
return 0;
}

His blog
Good luck if it helps Smile
Back to top
View user's profile Send private message MSN Messenger
--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?

PostPosted: Thu Jan 03, 2008 2:57 pm    Post subject: Reply with quote

lurc, I have the .net framework, I attached the installer below.
monsoon, thnaks, it's slightly different to how everyone else has been doing it.

_________________

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
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Thu Jan 03, 2008 9:08 pm    Post subject: Reply with quote

you may need .NET Framework 3.5 seeing as i compiled it using VS2008

http://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&displaylang=en

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Jan 03, 2008 11:31 pm    Post subject: Reply with quote

It's a native application, not managed, it won't need the framework.
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Fri Jan 04, 2008 12:59 am    Post subject: Reply with quote

Instead, it will need the Microsoft visual C++ 2005/2008 redistributable package.

2005

2008

_________________
Back to top
View user's profile Send private message
kittonkicker
I post too much
Reputation: 1

Joined: 19 Apr 2006
Posts: 2171

PostPosted: Sun Jan 06, 2008 5:18 am    Post subject: Reply with quote

I thought the whole idea of SendInput was that you could send more than one command at the same time?

Code:
INPUT aInput[2];

memset(aInput, 0, sizeof(INPUT)*2); //note: I removed the & before aInput because I defined aInput as an array of INPUTs

aInput[0].type = INPUT_MOUSE;
aInput[0].mi.mouseData = 0;
aInput[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
aInput[0].mi.dwExtraInfo = 0;
aInput[0].mi.time = 0;

aInput[1].type = INPUT_MOUSE;
aInput[1].mi.mouseData = 0;
aInput[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
aInput[1].mi.dwExtraInfo = 0;
aInput[1].mi.time = 0;

SendInput(2, aInput, sizeof(INPUT));


Also, instead of redefining what aInput is each time you want to send a click, surely you could just define it in your header and then reference it in SendInput()?

I'd understand the need to redefine if you were going to be sending a different key each time, but it seems like wasted CPU power to me!

_________________
All gone Sad
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 Previous  1, 2, 3  Next
Page 2 of 3

 
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