怎么用c#代码模拟鼠标单击,像按键精灵一样

cao748438 2010-10-25 08:49:48
各位,我想实现QQ视频的自动接受,然后就想如果能模拟鼠标单击视频的那个“接受”按钮就可以了。但是不行,大体代码如下,大家帮忙看看,或有什么参考资料,谢谢啊。
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr window, int message, int wparam, int lparam);

[DllImport("user32", CharSet = CharSet.Auto)]
public extern static int SendMessage(IntPtr hWnd, int wMsg, int wParam, string lpstring);

[DllImport("user32.dll")]
public static extern int PostMessage(IntPtr window, int message, int wparam, int lparam);

[DllImport("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]
public static extern void SetForegroundWindow(IntPtr hwnd);

public const int MOUSEEVENTF_LEFTDOWN = 0x21;
public const int MOUSEEVENTF_LEFTUP = 0x202;

int x = 455;//x,y是用spy++截取到的
int y = 300;

IntPtr iHandle = FindWindow("TXGuiFoundation", "视频界面的名字");//能够成功获取窗口句柄
SetForegroundWindow(iHandle1);
//一点反应也没有
SendMessage(iHandle, MOUSEEVENTF_LEFTDOWN, 0, x + (y << 16));
SendMessage(iHandle, MOUSEEVENTF_LEFTUP, 0, x + (y << 16));

//用下面这种方式也不行
// int result1=Win32.PostMessage(iHandle1, MOUSEEVENTF_LEFTDOWN, 0, x + (y << 16));
//int result2= Win32.PostMessage(iHandle1, MOUSEEVENTF_LEFTUP, 0, x + (y << 16));

以下是我用spy++获取的信息
<01886> 00090864 S WM_SETFOCUS hwndLoseFocus:(null)
<01887> 00090864 R WM_SETFOCUS
<01888> 00090864 R WM_ACTIVATE
<01889> 00090864 S WM_SETCURSOR hwnd:00090864 nHittest:HTCLIENT wMouseMsg:WM_LBUTTONDOWN
<01890> 00090864 R WM_SETCURSOR fHaltProcessing:False
<01891> 00090864 P WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:452 yPos:301
//以下应该不是了,有人说QQ界面的按钮是自绘的,下面也真有WM_PAINT消息,但是貌似没什么关系吧?
<01892> 00090864 S WM_PAINT hdc:00000000
<01893> 00090864 R WM_PAINT
<01894> 00090864 P WM_MOUSEMOVE fwKeys:MK_LBUTTON xPos:452 yPos:301
<01895> 00090864 P WM_PAINT hdc:00000000
<01896> 00090864 P WM_LBUTTONUP fwKeys:0000 xPos:452 yPos:301
<01897> 00090864 S WM_CAPTURECHANGED hwndNewCapture:00000000
<01898> 00090864 R WM_CAPTURECHANGED
<01899> 00090864 S WM_PARENTNOTIFY fwEvent:WM_CREATE idChild:0001 (1) hwndChild:00090416
<01900> 00090864 R WM_PARENTNOTIFY
<01901> 00090864 S WM_PARENTNOTIFY fwEvent:WM_CREATE idChild:0001 (1) hwndChild:00090528
<01902> 00090864 R WM_PARENTNOTIFY

各位大哥,有什么方法不?还是我哪边错了?还是压根没什么办法?谢谢各位了!
...全文
1335 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
mirtc 2012-05-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
VB.NET code


UserVar Var1=DropList{8000:8000|10000:10000|15000:15000}=1 打多长时间
Rem denga
Rem 看人出来没有
IfColor 85,57,20ea6,0
Else
Delay 1000
Goto denga
EndIf
Rem 食技能珠
MoveTo 610,10
……
[/Quote]
人家就用这方法
水碎了 2011-11-17
  • 打赏
  • 举报
回复
怎么不贴你的方法啊
gdh21cn 2010-11-04
  • 打赏
  • 举报
回复
妈的,就知道自己搞定
cao748438 2010-10-25
  • 打赏
  • 举报
回复
终于搞定了,最后用了SetCursorPos和mouse_event。谢谢各位了。
wuyq11 2010-10-25
  • 打赏
  • 举报
回复
using System.RunTime.InteropServices;

private const int WM_LBUTTONDOWN = 513; // 0x0201
private const int WM_LBUTTONUP = 514; // 0x0202
[System.Runtime.InteropServices.DllImport( "user32.dll ")]
static extern bool SendMessage(IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam);

private void SetNoCurrentCell()
{

SendMessage(Form2.Handle, WM_LBUTTONDOWN, 0, 0);
SendMessage(Form2.Handle, WM_LBUTTONUP, 0, 0);
}

http://topic.csdn.net/u/20090106/12/8c4c1a5d-4e99-4f3f-b0cd-e1c0129e2a29.html
ajq1989 2010-10-25
  • 打赏
  • 举报
回复


UserVar Var1=DropList{8000:8000|10000:10000|15000:15000}=1 打多长时间
Rem denga
Rem 看人出来没有
IfColor 85,57,20ea6,0
Else
Delay 1000
Goto denga
EndIf
Rem 食技能珠
MoveTo 610,10
Delay 200
LeftClick 1
Delay 300
KeyPress 73,1
Delay 200
VBSCall FindColorEx(1121,452,1231,631,"3436ff",0,0.8,a,b)
Delay 100
MoveTo a,b
Delay 100
RightClick 1
Delay 200
KeyPress 73,1
Delay 200
KeyPress 119,1
Rem 等待开始
Rem 点外挂传送要挂机的地方
Rem 判断开始出现
IfColor 870,912,5050ff,0
Else
Delay 100
Goto 等待开始
EndIf
Rem Delay 100
Rem MoveTo 269,765
Rem Delay 100
Rem LeftClick 1
Rem Delay 200
Rem MoveTo 610,10
Rem Delay 200
Rem LeftClick 1
Rem Delay 300
Rem KeyPress 119,1
Rem 边打边判断蓝多少 共8秒
IfColor 137,72,222222,0
KeyPress 187,1
Else
EndIf
Delay 1000
IfColor 137,72,222222,0
KeyPress 187,1
Else
EndIf
Delay 1000
IfColor 137,72,222222,0
KeyPress 187,1
Else
EndIf
Delay 1000
IfColor 137,72,222222,0
KeyPress 187,1
Else
EndIf
Delay 1000
IfColor 137,72,222222,0
KeyPress 187,1
Else
EndIf
Delay 1000
IfColor 137,72,222222,0
KeyPress 187,1
Else
EndIf
Delay 1000
IfColor 137,72,222222,0
KeyPress 187,1
Else
EndIf
Delay 1000
IfColor 137,72,222222,0
KeyPress 187,1
Else
EndIf
Delay 1000
KeyPress 119,1
Rem 判断有没有死亡
IfColor 80,56,151da8,1
Delay 200
KeyPress 119,1
Delay 2000
MoveTo 639,393
Delay 2000
LeftClick 1
Delay 2000
For 2
KeyPress 27,1
EndFor
IfColor 613,313,f3973d,0
MoveTo 636,409
Delay 1000
LeftClick 1
Goto dang
Else
EndIf
Else
EndIf
Rem 判断有没有断线
IfColor 437,262,b12ee,0
VBSCall RunApp("D:\迅雷广告绿色\Program\download-complete.wav")
EndScript
Else
EndIf
KeyPress 27,1
Delay 200
MoveTo 636,409
Delay 20
LeftClick 1
Rem dang
Rem deng
IfColor 1025,385,eeeeee,0
Else
Delay 1000
Goto deng
EndIf
For 3
KeyPress 13,1
Delay 100
EndFor
Delay 500

cao748438 2010-10-25
  • 打赏
  • 举报
回复
怎么没人?自己顶。

111,119

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧