Clicking mouse by sending messages
Posted
by Frank Meulenaar
on Stack Overflow
See other posts from Stack Overflow
or by Frank Meulenaar
Published on 2010-05-12T11:11:16Z
Indexed on
2010/05/12
11:14 UTC
Read the original article
Hit count: 159
I'm trying to send mouse clicks to a program. As I don't want the mouse to move, I don't want to use SendInput or mouse_event, and because the window that should receive the clicks doesn't really use Buttons or other GUI events, I can't send messages to these buttons.
I'm trying to get this working using SendMessage, but for some reason it doesn't work. Relevant code is (in C#, but tried Java with jnative as well), trying this on Vista
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(IntPtr A_0, int A_1, int A_2, int A_3);
static int WM_CLOSE = 0x10;
static int WM_LBUTTONDOWN = 0x201;
static int WM_LBUTTONUP = 0x202;
public static void click(IntPtr hWnd, int x, int y)
{
SendMessage(hWnd, WM_LBUTTONDOWN, 1, ((x << 0x10) ^ y));
SendMessage(hWnd, WM_LBUTTONUP, 0, ((x << 0x10) ^ y));
}
public static void close(IntPtr hWnd)
{
SendMessage(hWnd, WM_CLOSE, 0, 0);
}
The close
works fine, but the click
doesn't do anything.
© Stack Overflow or respective owner