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 =)