SendMessage发送鼠标单击事件
我想向一个网页的某一位置发送一个鼠标单击信息,就是想用程序来按网页,我找过很多资料,都只能按到按钮,但我想是按到一个位置(位置上可能是图片,文字,或超级链接),有什么方法...
我想向一个网页的某一位置发送一个鼠标单击信息,就是想用程序来按网页,我找过很多资料,都只能按到按钮,但我想是按到一个位置(位置上可能是图片,文字,或超级链接),有什么方法?
这段是我写的,可是不行:
g_WindowHwnd = FindWindow(vbNullString, "XXX - Windows Internet Explorer")
hWnd1 = g_WindowHwnd
Dim x As Integer, y As Integer, res As Long
x = Int(Text1.Text)
y = Int(Text2.Text)
Dim r1, r2 As Long
res = (y * &H10000) + x
r1 = SendMessage(hWnd1, WM_LBUTTONDOWN, MK_LBUTTON, ByVal res)
r2 = SendMessage(hWnd1, WM_LBUTTONUP, MK_LBUTTON, ByVal res)
(句柄没问题)
最后100分,谢谢. 展开
这段是我写的,可是不行:
g_WindowHwnd = FindWindow(vbNullString, "XXX - Windows Internet Explorer")
hWnd1 = g_WindowHwnd
Dim x As Integer, y As Integer, res As Long
x = Int(Text1.Text)
y = Int(Text2.Text)
Dim r1, r2 As Long
res = (y * &H10000) + x
r1 = SendMessage(hWnd1, WM_LBUTTONDOWN, MK_LBUTTON, ByVal res)
r2 = SendMessage(hWnd1, WM_LBUTTONUP, MK_LBUTTON, ByVal res)
(句柄没问题)
最后100分,谢谢. 展开
4个回答
展开全部
One Possible Answer:
Change SendMessage into mouse_event
{
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Call mouse_event(&H2, 0, 0, 0, 0)
Call mouse_event(&H4, 0, 0, 0, 0)
}
Change SendMessage into mouse_event
{
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Call mouse_event(&H2, 0, 0, 0, 0)
Call mouse_event(&H4, 0, 0, 0, 0)
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
c#的代码:
[DllImport("user32", EntryPoint = "SetCursorPos")]
public extern static void SetCursorPos(int x, int y);
[DllImport("user32", EntryPoint = "mouse_event")]
public extern static void Mouse_Event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);
public enum MouseEventFlags
{
LeftDown = 0x0002,
LeftUp = 0x0004,
Absolute = 0x8000
}
//int x ,y为横坐标与纵坐标
public void MouseMoveClick(int x, int y)
{
SetCursorPos(x, y);
Win32API.Mouse_Event((int)(MouseEventFlags.LeftDown | MouseEventFlags.Absolute),0,0,0,IntPtr.Zero);
Win32API.Mouse_Event((int)(MouseEventFlags.LeftUp | MouseEventFlags.Absolute), 0, 0,0,IntPtr.Zero);
}
[DllImport("user32", EntryPoint = "SetCursorPos")]
public extern static void SetCursorPos(int x, int y);
[DllImport("user32", EntryPoint = "mouse_event")]
public extern static void Mouse_Event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);
public enum MouseEventFlags
{
LeftDown = 0x0002,
LeftUp = 0x0004,
Absolute = 0x8000
}
//int x ,y为横坐标与纵坐标
public void MouseMoveClick(int x, int y)
{
SetCursorPos(x, y);
Win32API.Mouse_Event((int)(MouseEventFlags.LeftDown | MouseEventFlags.Absolute),0,0,0,IntPtr.Zero);
Win32API.Mouse_Event((int)(MouseEventFlags.LeftUp | MouseEventFlags.Absolute), 0, 0,0,IntPtr.Zero);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你很厉害。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以写个程序操作鼠标啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询