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 


Noob C++ question

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Wed Oct 22, 2008 12:47 pm    Post subject: Noob C++ question Reply with quote

Hey all, i currently have to following code for my autoshooter ( not aimbot).

Code:

int main()
{
   while(1)
       {
             Sleep(10);
             if(GetAsyncKeyState(VK_F9)&1)
             {
                         my code
                  }
        }
return 0;
}


When i press f9, it executes "my code" once. But now, i want that when i press F9 once, it keeps executing "my code" , and when i press F10, it stops executing mycode.
I thought of something like
i


Code:

if(GetAsyncKeyState(VK_F9)&1)
    BOOL a = TRUE;
if(GetAsyncKeyState(VK_F10)&1)
    BOOL a = FALSE;
while(a)
{
my code
}




but that doesn't seem to work... Can anyone give me some help?
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Wed Oct 22, 2008 1:33 pm    Post subject: Reply with quote

I think it's something like this:
Code:
bool a;

if(GetAsyncKeyState(VK_F9)&1)
                a = true;
else if(GetAsyncKeyState(VK_F10)&1)
                a = false;

while(a == true)
{
                my code
}
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Oct 22, 2008 2:02 pm    Post subject: Reply with quote

Follow the code, you will never get out of the loop to check the key state.
Back to top
View user's profile Send private message MSN Messenger
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Wed Oct 22, 2008 2:05 pm    Post subject: Reply with quote

Don't forget your brackets -> { }
Hehe!

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Wed Oct 22, 2008 2:47 pm    Post subject: Reply with quote

Code:
#include <windows.h>

bool Whatever = false;

int main()
{
     while(true)
     {
          if (GetAsyncKeyState(VK_F9) && Whatever == false)
          {
               Whatever = true;
               Sleep(250);
          }
          else if (GetAsyncKeyState(VK_F9) && Whatever == true)
          {
               Whatever = false;
               Sleep(250);
          }
          if (Whatever == true)
          {
               //code here
          }
     }
     return 0;
}

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Oct 22, 2008 3:01 pm    Post subject: Reply with quote

HornyAZNBoy wrote:
Code:
#include <windows.h>

bool Whatever = false;

int main()
{
     while(true)
     {
          if (GetAsyncKeyState(VK_F9) && Whatever == false)
          {
               Whatever = true;
               Sleep(250);
          }
          else if (GetAsyncKeyState(VK_F9) && Whatever == true)
          {
               Whatever = false;
               Sleep(250);
          }
          if (Whatever == true)
          {
               //code here
          }
     }
     return 0;
}


Into this:

Code:
#include <windows.h>
#pragma comment(lib, "user32.lib")

int main( void )
{
    bool Whatever = false;
    for( ;;Sleep(10) )
    {
        if( GetAsyncKeyState(VK_F9)&01 ) {
         Whatever ^= true;
        }
        if( Whatever == true ) {
               // True
        } else {
          // False
        }
    }
    return 0;
}
Back to top
View user's profile Send private message MSN Messenger
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Wed Oct 22, 2008 3:58 pm    Post subject: Reply with quote

Code:
for(;;) {
    if(GetAsyncKeyState(VK_F9))
        for(;!GetAsyncKeyState(VK_F10);) {
            ...
        }
}


Insert sleeps, and correct any errors with API usage since I haven't used win32 in quite awhile.

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Thu Oct 23, 2008 8:44 am    Post subject: Reply with quote

RegisterHotKey...
Back to top
View user's profile Send private message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Thu Oct 23, 2008 9:33 am    Post subject: Reply with quote

Tnx all. Don't really know how RegisterHotkey works so i used GetAsyncKeyState.

Anyway, here is my code. It's working for the game CounterStrike2D. But i think it can be improved.

Code:

#include <windows.h>
#include <iostream>

using namespace std;


int main()
{
   bool Whatever = false;
   bool Team = false; //false for CT, true for T
   cout << "Welcome to CS2D Autoshooter" ;
   
   while(true)
   {
      if(GetAsyncKeyState(VK_F9) && Whatever == false)
      {
         Whatever = true;
         Sleep(250);
      }
      else if (GetAsyncKeyState(VK_F9) && Whatever == true)
      {
         Whatever = false;
         Sleep(250);
      }
      if(GetAsyncKeyState(VK_F4) && Team == false)
      {
         Team = true;
         Sleep(250);
      }
      else if (GetAsyncKeyState(VK_F4) && Team == true)
      {
         Team = false;
         Sleep(250);
      }

      if (Whatever == true)
      {
         Sleep(10);
         HWND hWnd;
         hWnd = FindWindow(NULL, "Unreal Software's Counter-Strike 2D"); // can i place this outside the loop?
      
         if(hWnd == NULL)
         {
            cout << "CounterStrike2D is not opened!\n";
         }
         else
         {
      
            
            POINT pos;
            GetCursorPos(&pos);
            HDC hScreenDC = GetDC(hWnd);
            COLORREF rgb = GetPixel(hScreenDC, pos.x, pos.y);
            ReleaseDC(hWnd, hScreenDC);
            UINT red = GetRValue (rgb);
            UINT green = GetGValue (rgb);
            UINT blue = GetBValue (rgb);
            
            if(Team == true)
            {
               if(red==255 && blue==0)
               {
                  cout << rgb << endl;
                  mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
                  mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
               }
            }
            else
            {
               if(blue==255 && red==0)
               {
                  cout << rgb << endl;
                  mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
                  mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
               }
            }

            rgb = 000;
      
         }
      }
   }
   return 0;
}



I am currently trying to make an aimbot using an entirely different method. OpenGL Hooking.
But i cannot figure out how to get coordinates of X,Y models.
I thought they were placed onto the screen with glOrtho().
I read some tutorials about wrappers and client hooks but they are mostly for normal CounterStrike, source.
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
Page 1 of 1

 
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