Click here to Skip to main content
15,891,764 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ok so im Trying to send Keys, in this case Mouse button, but when its injected ect it wont send? any help would be good, thanks.


C++
//==============================//
//Project: Send Keys            //
//==============================//

// Define
#define IsKeyDown(Key) GetAsyncKeyState(Key) & 0x8000 //Used to check if a key is down.


// Include headers
#include <windows.h>
#include <iostream>
#include <tchar.h>
#pragma comment(lib,"User32.lib")

///////std
using namespace std;

// Global Vars //
DWORD dwGameExe = NULL;
bool bFire = false;
bool on1 = true;
//thread - key send and sh*t.. for checks
DWORD WINAPI dwMainThread(LPVOID)
{
	 //Check for the game
	for(;dwGameExe == NULL; Sleep(250)); // if exe is still null.. Sleep until game is found
	{
		dwGameExe = (DWORD)GetModuleHandle("notepad.exe");// Retrieves the module of "BFBC2Game.exe"
		//dwGameExe = (DWORD)GetModuleHandle("TESV.exe")
	}		
	// Do key checks etc.

//if (IsKeyDown(VK_LBUTTON))
if (IsKeyDown(VK_F2))
//if (IsKeyDown(MOUSEEVENTF_LEFTDOWN))
		on1 = !on1;

	if(on1 == true)
{
	
Sleep(100);


mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Sleep(100);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
//Sleep(80);


Sleep(100);



mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Sleep(100);
	mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
//Sleep(80);



//	mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
//	Sleep(10);
//	mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);

return 1;

}



	if(GetAsyncKeyState(VK_UP)&1) // F1 Hot keey to enable.. then let it see if it fires.
		bFire = !bFire;

	if(bFire == true)
	{
		mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
		Sleep(2500);
		mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);

MessageBox(NULL,"Project1.dll detached to Process!", "Successful Injection" ,NULL);

	}

	return 1;
}

BOOL WINAPI DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
    switch (dwReason)
    {
        case DLL_PROCESS_ATTACH:
            // Call thread
			CreateThread(0,0,dwMainThread,0,0,0);
			MessageBox(NULL,"Project1.dll detached to Process!", "Successful Injection" ,NULL);
            break;

        case DLL_PROCESS_DETACH:
            // Code to run when the DLL is freed
            break;
    }
    return TRUE;
}
Posted
Comments
Addy Tas 14-Dec-11 17:43pm    
Please cleanup the code dump and try to specify what does and what does not work
Cheers, AT
jenkinsss 14-Dec-11 20:40pm    
im trying to make it Send a Key press, in this case the mouse button, it injects into the game but it dose not Send the key,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900