日期:2014-05-18  浏览次数:20840 次

怎么用c#代码模拟鼠标单击,像按键精灵一样
各位,我想实现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

各位大哥,有什么方法不?还是我哪边错了?还是压根没什么办法?谢谢各位了!
 

------解决方案--------------------
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
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 13