I posted yesterday with some questions about making a mouse utility to replace the double click with a single keystroke. I finally put it all together, and came up with this DLL:

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

HHOOK hook = 0;
bool quit = false;
LRESULT CALLBACK ClickProc(int disabled, WPARAM wparam, LPARAM lparam);
HMODULE modcpy;

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	modcpy = hModule;
	return TRUE;
}
extern "C" __declspec(dllexport) void Install()
{
    hook = SetWindowsHookEx(WH_MOUSE, ClickProc, modcpy, 0);
    MSG msg;
	Beep(660, 100);
	if(hook != 0)  //Hook Succeeded
	{
		Beep(880, 300);
	}
	else           //Hook Failed
	{
		Beep(440, 300);
	}
	while(GetMessage(&msg,0,0,0) && (quit==false))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
}
LRESULT CALLBACK ClickProc(int disabled, WPARAM wparam, LPARAM lparam)
{
	
	if(wparam == WM_LBUTTONDBLCLK)
	{
		Beep(110, 30);
		INPUT Input;

		ZeroMemory(&Input, sizeof(INPUT));

		Input.type = INPUT_KEYBOARD;
		Input.ki.dwFlags = KEYEVENTF_SCANCODE;
		Input.ki.wScan = MapVirtualKey(VK_NUMPAD0, 0);

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

		ZeroMemory(&Input, sizeof(INPUT));

		Input.type = INPUT_KEYBOARD;
		Input.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
		Input.ki.wScan = MapVirtualKey(VK_NUMPAD0, 0);

		SendInput(1, &Input, sizeof(INPUT));
	}
	return CallNextHookEx(hook, 0, wparam, lparam);
}

I am having a few problems, with it though.

The hooking part seems to be completely global in windows, meaning that It picks it up no matter where I double click, but it doesn't pick up the clicks when I have Call of Duty 4 opened, which is the main reason I made this =(

also, SendInput will only work completely globally when I use it in an executable file and run as administrator. How can I give a DLL administrative privileges?

Thanks for any help =)

The hooking part seems to be completely global in windows, meaning that It picks it up no matter where I double click, but it doesn't pick up the clicks when I have Call of Duty 4 opened, which is the main reason I made this =(

Maybe Call of Duty 4 places it's own hooks for a mouse events and messages. In this case I see one way to solve your problem - make a filter driver, which attaches into mouse driver stack, and hooks some mouse messages/events.

you know what? I think I might have to take your advice and try making my own mouse driver instead...It just occured to me, that they probably use Direct Input and skip windows and all its hooks and whatnot completely...

Is there any way to intercept Direct Input from another program if thats it? I imaging that would be difficult if even possible...

How hard can it be to make a simple driver though? I hope I'm not sorry I asked..lol

thanks 4 the help

This article has been dead for over six months. Start a new discussion instead.