问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace鼠标点击{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}constintMOUSEEVENTF_LEFTDOWN=0x0002;//模拟鼠标左键按下constintMOUSEEVENTF_LEFTUP=0x0004;//模拟鼠标左键抬起[System.Runtime.InteropServices.DllImport("user32")]privatestaticexternintmouse_event(intdwFlags,intdx,intdy,intcButtons,intdwExtraInfo);privatevoidbutton1_Click(objectsender,EventArgse){Buttonbtn=senderasButton;if(button1.Text=="开始"){timer1.Start();button1.Text="停止";}else{timer1.Stop();button1.Text="开始";}}privatevoidtimer1_Tick(objectsender,EventArgse){intx=MousePosition.X;//获取鼠标的x坐标inty=MousePosition.Y;//获取鼠标的y坐标mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP,x,y,0,0);}}}为什么moust_event返回1,返回1表示没有执行成功么?
解决方案
解决方案二:
VOIDmouse_event(DWORDdwFlags,DWORDdx,DWORDdy,DWORDdwData,ULONG_PTRdwExtraInfo);
这是函数原型