From: bob on
How do you generate a mouse click in a windows environment? I can read
the output of the mouse but would like to program a double click event,

at best through generating two left clicks fast after each other by
software, not the hard way. I know that mouse clicker software exists
which can time artificial clicks.

My plan is to read a middle click and convert it into a double left
click.

From: JustBoo on
On 28 Jan 2006 10:04:52 -0800, "bob" <drfabius2000(a)hotmail.com> wrote:

>How do you generate a mouse click in a windows environment?

LRESULT SendMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to send
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

So:
Msg = WM_LBUTTONDOWN; sends a mouse click to Windows.

>I can read
>the output of the mouse but would like to program a double click event,

Msg = WM_LBUTTONDBLCLK;

>at best through generating two left clicks fast after each other by
>software, not the hard way. I know that mouse clicker software exists
>which can time artificial clicks.

Msg = WM_LBUTTONDBLCLK;
Msg = WM_MBUTTONDBLCLK;
Msg = WM_RBUTTONDBLCLK;

There are more mouse messges as well. Search for "WM_" and browse.

HTH - Good Luck
From: Lucian Wischik on
"bob" <drfabius2000(a)hotmail.com> wrote:
>How do you generate a mouse click in a windows environment? I can read
>the output of the mouse but would like to program a double click event,
>at best through generating two left clicks fast after each other by
>software, not the hard way. I know that mouse clicker software exists
>which can time artificial clicks.

It sounds like you want to make this change system-wide, ie. not just
for your program. (if you wanted to do it just for your own program,
it would be easy! just respond to WM_MBUTTONDOWN by invoking your own
left-click-double-handler.)

If you want to do it system-wide, you would intercept the mouse click
by installing a low-level mouse handler. And you'd spoof the
double-click by using the SendInput command. I wrote the following
program which does something similar, but it intercepts the right menu
key on the keyboard and generates a single right-click event.

--
Lucian




#define _WIN32_WINNT 0x0500
#include <windows.h>

// This program installs a "low level keyboard hook".
// Whenever the right alt key (VK_RMENU) goes down, we generate a
right-mouse-down event.
// When the right alt key goes up, we generate a right-mouse-up event.
// To respond to other keypresses instead, look in winuser.h
//
// Generation of events is by SendInput(..), a Windows NT/2k/XP
function.
//
// The keyboard hook is installed with
SetWindowsHookEx(WH_KEYBOARD_LL,...),
// which is also specific to NT/2k/XP. This hook has the nice feature
that it
// can "gobble up" keyboard events, so they're not seen by the rest of
the system.
// Note: WH_KEYBOARD_LL always sets a global hook and so works for all
applications.
// But unlike most global hooks (which have to reside in a DLL), the
WH_KEYBOARD_LL
// can instead reside in an EXE. What Windows does is, whenever it
receives a keypress,
// it switches to the context of the EXE that contained the hook, then
invokes the hook
// function, then restores context back to what it was before.
//
// The main routine sets the hook, then creates an invisible top-level
window, and when
// the top-level window gets closed (by ending it in the TaskManager),
we unhook the hook.
// Note: it might seem nicer not to have any window at all, and just
to enter an infinite
// loop. But (1) with a window we can exit more gracefully (and we can
also choose to
// appear in the Process List of the taskmanager). And (2) keyboard
hooks fail to work
// when there's just a tight infinite loop of Sleep(). It just wasn't
working. Then when
// I created the window and did a message-loop it magically started
working. My guess
// is that the context-switching might internally use the message-loop
mechanism,
// or something like that.


LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM
lParam)
{ PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT)lParam;
//
if (nCode==HC_ACTION && p->vkCode==VK_RMENU && (wParam==WM_KEYDOWN
|| wParam==WM_SYSKEYDOWN))
{ INPUT ip; ZeroMemory(&ip,sizeof(ip)); ip.type=INPUT_MOUSE;
ip.mi.dwFlags=MOUSEEVENTF_RIGHTDOWN;
SendInput(1,&ip,sizeof(ip)); return 1;
}
if (nCode==HC_ACTION && p->vkCode==VK_RMENU && (wParam==WM_KEYUP ||
wParam==WM_SYSKEYUP))
{ INPUT ip; ZeroMemory(&ip,sizeof(ip)); ip.type=INPUT_MOUSE;
ip.mi.dwFlags=MOUSEEVENTF_RIGHTUP;
SendInput(1,&ip,sizeof(ip)); return 1;
}
return CallNextHookEx(0,nCode,wParam,lParam);
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
lParam)
{ if (msg==WM_DESTROY) PostQuitMessage(0);
return DefWindowProc(hwnd, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR,int)
{ HHOOK hook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc,
hInstance, 0);
//
WNDCLASSEX wcex; ZeroMemory(&wcex,sizeof(wcex));
wcex.cbSize=sizeof(WNDCLASSEX);
wcex.lpfnWndProc=(WNDPROC)WndProc; wcex.hInstance=hInstance;
wcex.lpszClassName=L"KeyboardMouseClass";
RegisterClassEx(&wcex);
CreateWindowEx(0,L"KeyboardMouseClass",
L"KeyboardMouse",0,0,0,0,0,0,0,hInstance,0);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {TranslateMessage(&msg);
DispatchMessage(&msg);}
//
UnhookWindowsHookEx(hook);
return msg.wParam;
}



From: Barry on

"bob" <drfabius2000(a)hotmail.com> wrote in message
news:1138471492.622877.149600(a)g14g2000cwa.googlegroups.com...
> How do you generate a mouse click in a windows environment? I can read
> the output of the mouse but would like to program a double click event,
>
> at best through generating two left clicks fast after each other by
> software, not the hard way. I know that mouse clicker software exists
> which can time artificial clicks.
>
> My plan is to read a middle click and convert it into a double left
> click.
>

The mouse_event function synthesizes mouse motion and button clicks.

VOID mouse_event(

DWORD dwFlags, // flags specifying various motion/click variants
DWORD dx, // horizontal mouse position or position change
DWORD dy, // vertical mouse position or position change
DWORD dwData, // amount of wheel movement
DWORD dwExtraInfo // 32 bits of application-defined information
);


From: kaychoro on
I've run into a similar problem. My thought was to just do as much
manually as I could - a MOUSEEVENTF_LEFTDOWN then MOUSEEVENTF_LEFTUP.
Using this method, should I be able to simulate the click on the File
menu of my app?

Thanks,
Kaychoro

------------------------------------------------------------------------------
input[0].type = INPUT_MOUSE;
input[0].mi.dx = 0;
input[0].mi.dy = 0;
input[0].mi.mouseData = 0;
input[0].mi.time = 0;
input[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
input[1].type = INPUT_MOUSE;
input[1].mi.dx = 0;
input[1].mi.dy = 0;
input[1].mi.mouseData = 0;
input[1].mi.time = 0;
input[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(2, input, sizeof (input[0].mi));