C++ 6.0 Hotkeys

Posts 1–15 of 22 · Page 1 of 2
C++ 6.0 Hotkeys
Hello, Im pretty known to how C++ works now. I use 6.0. I'm been learning how to program for some time, making trainers for Counter-Strike Source.

My problem is that I know how to make the hacks working with buttons, but lets say I didn't want to make buttons and I wanted to make Hotkeys? How would I do that? Do I need to do a timer like in VB?

I have the list of all hotkeys and I know the code should look like this.

Example:

Code:
if (GetKeyState(VK_RBUTTON) &1)
{
//Code here
}
But where is this code suppost to go if im not going to use buttons?
I forgot to mention, can you show me examples on how it should look like?
You could always create a thread and keep checking if any keys have been pressed. Example:

Code:
void Hotkey()
{
     while(1)
     {
             if(GetAsyncKeyState(/*vk key code*/))
             {
                                      Hack();
             }
     }
}
And for the thread it's something like this:

Code:
CreateThread(0,0,(LPTHREAD_START_ROUTINE)Hotkey,0,0,0);
If you're not familiar with threads, check this out Threads

I made this off the top of my head by the way.
Quote Originally Posted by Void View Post
You could always create a thread and keep checking if any keys have been pressed. Example:

Code:
void Hotkey()
{
     while(1)
     {
             if(GetAsyncKeyState(/*vk key code*/))
             {
                                      Hack();
             }
     }
}
And for the thread it's something like this:

Code:
CreateThread(0,0,(LPTHREAD_START_ROUTINE)Hotkey,0,0,0);
If you're not familiar with threads, check this out Threadsⓘ

I made this off the top of my head by the way.
Ok, but for example where would this code go?

Code:
Writelong(0x943A16, 1);
Code:
void Hotkey()
{
     while(1)
     {
             if(GetAsyncKeyState(/*vk key code*/))
             {
                     Writelong(0x943A16, 1);                
             }
     }
}
Try that.
Quote Originally Posted by Void View Post
Code:
void Hotkey()
{
     while(1)
     {
             if(GetAsyncKeyState(/*vk key code*/))
             {
                     Writelong(0x943A16, 1);                
             }
     }
}
Try that.
Ok thanks I will try it but, isnt it GetKeyState instead of GetAsyncKeyState?
Ok thanks I will try it but, isnt it GetKeyState instead of GetAsyncKeyState?
They both work, I've always used GetAsyncKeyState();
Quote Originally Posted by Void View Post
They both work, I've always used GetAsyncKeyState();
ok, and lets I wanted to add another hotkey to a second hack? how would I add it? Meaning how would I put another hack with a hotkey on the same trainer.
I thought you said you had some experience?

Code:
void Hotkey()
{
     while(1)
     {
             if(GetAsyncKeyState(/*vk key code*/))
             {
                     Writelong(0x943A16, 1);                
             }
             
             if(GetAsyncKeyState(/*another vk key code*/))
             {
                     Writelong(0xAddress, 1);                
             }
     }
}
Quote Originally Posted by Void View Post
I thought you said you had some experience?

Code:
void Hotkey()
{
     while(1)
     {
             if(GetAsyncKeyState(/*vk key code*/))
             {
                     Writelong(0x943A16, 1);                
             }
             
             if(GetAsyncKeyState(/*another vk key code*/))
             {
                     Writelong(0xAddress, 1);                
             }
     }
}
Ok thanks, but something seems to be wrong, I build it, and I get no errrors which is good, but the hotkeys seems not to be working, when I use buttons, on my other trainer that I just made now the hacks work so it has not been patched or detected.

This is the CSS Process.


Code:
DWORD proc_id;
HANDLE hProcess;

void memory()
{
HWND hWnd = FindWindow(0, "Counter-Strike Source");
GetWindowThreadProcessId(hWnd, &proc_id);
hProcess = OpenProcess(PROCESS_ALL_ACCESS|PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, proc_id);
}
void Writelong(long addy, long value)
{
memory();
WriteProcessMemory(hProcess, (LPVOID*)(DWORD) addy, &value, sizeof(value), NULL);

}
void WritePointerFloat(long addy, short offset, float value)
{
long maddy;
long saddy;
memory();
ReadProcessMemory(hProcess, (LPVOID*)(DWORD) addy, &maddy, sizeof(maddy), NULL);
saddy = maddy + offset;
WriteProcessMemory(hProcess, (LPVOID*)(DWORD) saddy, &value, sizeof(value), NULL);
This is what I just did.

Code:
void Hotkey()
{
     while(1)
     {
             if(GetAsyncKeyState(VK_CONTROL))
             {
                     Writelong(0x243AEC3C, 2);                
             }
     }
}
First of all, stop double posting.

Second, let me see the full code. I'll fix it for you.
Sorry for the double posting. I appriciate your help. I know I called it "aaaaaaaaaaaa" but just testing it loooool.

Code:
// aaaaaaaaaaaaaaaaaDlg.cpp : implementation file
//

#include "stdafx.h"
#include "aaaaaaaaaaaaaaaaa.h"
#include "aaaaaaaaaaaaaaaaaDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

DWORD proc_id;
HANDLE hProcess;

void memory()
{
HWND hWnd = FindWindow(0, "Counter-Strike Source");
GetWindowThreadProcessId(hWnd, &proc_id);
hProcess = OpenProcess(PROCESS_ALL_ACCESS|PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, proc_id);
}
void Writelong(long addy, long value)
{
memory();
WriteProcessMemory(hProcess, (LPVOID*)(DWORD) addy, &value, sizeof(value), NULL);

}
void WritePointerFloat(long addy, short offset, float value)
{
long maddy;
long saddy;
memory();
ReadProcessMemory(hProcess, (LPVOID*)(DWORD) addy, &maddy, sizeof(maddy), NULL);
saddy = maddy + offset;
WriteProcessMemory(hProcess, (LPVOID*)(DWORD) saddy, &value, sizeof(value), NULL);
}

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAaaaaaaaaaaaaaaaaDlg dialog

CAaaaaaaaaaaaaaaaaDlg::CAaaaaaaaaaaaaaaaaDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAaaaaaaaaaaaaaaaaDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAaaaaaaaaaaaaaaaaDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CAaaaaaaaaaaaaaaaaDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAaaaaaaaaaaaaaaaaDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAaaaaaaaaaaaaaaaaDlg, CDialog)
	//{{AFX_MSG_MAP(CAaaaaaaaaaaaaaaaaDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_NOTIFY(NM_OUTOFMEMORY, IDC_HOTKEY1, OnOutofmemoryHotkey1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAaaaaaaaaaaaaaaaaDlg message handlers

BOOL CAaaaaaaaaaaaaaaaaDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CAaaaaaaaaaaaaaaaaDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CAaaaaaaaaaaaaaaaaDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		Ge***ientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CAaaaaaaaaaaaaaaaaDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void Hotkey()
{
     while(1)
     {
             if(GetAsyncKeyState(VK_CONTROL))
             {
                     Writelong(0x243AEC3C, 2);                
             }
     }
}
You didn't create a thread?

In your main function, create a thread.

Code:
CreateThread(0,0,(LPTHREAD_START_ROUTINE)Hotkey,0,0,0);
Quote Originally Posted by Void View Post
You didn't create a thread?

In your main function, create a thread.

Code:
CreateThread(0,0,(LPTHREAD_START_ROUTINE)Hotkey,0,0,0);
where do I add that? on the top?
Posts 1–15 of 22 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us