VBS脚本里,怎么控制鼠标在屏幕的某个坐标点单击?

请把程序打出来,谢谢拉。
麻烦写个例子给我看看,控制鼠标在屏幕的某点单击。

Option Explicit

Dim WshShell
Dim oExcel, oBook, oModule
Dim strRegKey, strCode, x, y
Set oExcel = CreateObject("Excel.Application") '创建 Excel 对象

set WshShell = CreateObject("wscript.Shell")

strRegKey = "HKEY_CURRENT_USER\So.tware\Microsoft\Office\$\Excel\Security\AccessVBOM"
strRegKey = Replace(strRegKey, "$", oExcel.Version)

WshShell.RegWrite strRegKey, 1, "REG_DWORD"

Set oBook = oExcel.Workbooks.Add '添加工作簿
Set oModule = obook.VBProject.VBComponents.Add(1) '添加模块
strCode = _

"'Author: Demon" & vbCrLf & _
"'Website: http://demon.tw" & vbCrLf & _
"'Date: 2011/5/10" & vbCrLf & _

"Private Type POINTAPI : X As Long : Y As Long : End Type" & vbCrLf & _
"Private Declare Function SetCursorPos Lib ""user32"" (ByVal x As Long, ByVal y As Long) As Long" & vbCrLf & _

"Private Declare Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long" & vbCrLf & _
"Private Declare Sub mouse_event Lib ""user32"" Alias ""mouse_event"" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)" & vbCrLf & _

"Public Function GetXCursorPos() As Long" & vbCrLf & _
"Dim pt As POINTAPI : GetCursorPos pt : GetXCursorPos = pt.X" & vbCrLf & _
"End Function" & vbCrLf & _

"Public Function GetYCursorPos() As Long" & vbCrLf & _
"Dim pt As POINTAPI: GetCursorPos pt : GetYCursorPos = pt.Y" & vbCrLf & _
"End Function"

oModule.CodeModule.AddFromString strCode '在模块中添加 VBA 代码
'Author: Demon
'Website: http://demon.tw
'Date: 2011/5/10
x = oExcel.Run("GetXCursorPos") '获取鼠标 X 坐标
y = oExcel.Run("GetYCursorPos") '获取鼠标 Y 坐标

WScript.Echo x, y
oExcel.Run "SetCursorPos", 30, 30 '设置鼠标 X Y 坐标
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_LEFTDOWN = &H2

Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40

Const MOUSEEVENTF_ABSOLUTE = &H8000
'模拟鼠标左键单击
oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

'模拟鼠标左键双击(即快速的两次单击)
oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

'模拟鼠标右键单击
oExcel.Run "mouse_event", MOUSEEVENTF_RIGHTDOWN + MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
'模拟鼠标中键单击
oExcel.Run "mouse_event", MOUSEEVENTF_MIDDLEDOWN + MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0

'关闭 Excel
oExcel.DisplayAlerts = False
oBook.Close
oExcel.Quit追问

有语法错误哎。
还有,非要建立Excel?.

温馨提示:内容为网友见解,仅供参考
第1个回答  2020-06-10
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_RIGHTUP = &H10
Const MOUSEEVENTF_RIGHTDOWN = &H8
Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, ByVal y As Integer) As Integer
Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
Function GetMouseXY() As String
Return System.Windows.Forms.Cursor.Position.X.ToString() & ":" & System.Windows.Forms.Cursor.Position.Y.ToString()
End Function
Private Sub SetMouseXY(ByVal x As Integer, ByVal y As Integer)
SetCursorPos(100, 200)
End Sub
SetCursorPos(x, y)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
第2个回答  2014-01-26
调用api就可以了
第3个回答  2011-10-31
是培训班用的吧 用按键精灵 编个下程序

VBS脚本里,怎么控制鼠标在屏幕的某个坐标点单击?
'模拟鼠标左键双击(即快速的两次单击)oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 oExcel.Run "mouse_event", MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 '模拟鼠标右键单击 oExcel.Run "mouse_event", MOUSEEVENTF_RIGHTDOWN + MOUSEEVEN...

vbs 鼠标怎么实现鼠标的移动和点击
第一步:找到按键精灵的安装目录里面的QMDispatch.dll(我用的是6.10其它版本名字应该没变吧)把它复制到system32目录;然后运行"regsvr32 QMDispatch.dll"注册控键,注册成功后会有提示.第一步:编一个只有下面的两句的VBS脚本运行一下看能不能移动鼠标 set obj = createobject("QMDispatch.QMFunction")obj....

vbs\/vb如何模拟鼠标点击
Const MOUSEEVENTF_RIGHTUP = &H10 '获取鼠标的位置 Dim p As POINTAPI Call GetCursorPos(p)Text1.Text = p.X Text2.Text = p.Y '设置鼠标的光标到坐标(431, 190)位置 ret = SetCursorPos(431, 190)'模拟一个左键单击的事件 mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0,...

...精灵脚本一个,可在某一确定时间在某一坐标点击左键。
'===以下是按键精灵录制的内容=== '===定义鼠标移动到的位置坐标=== MoveTo 123, 202 '===定义鼠标移动到位置坐标后等待时间(毫秒)=== Delay 1 '===点击左键一次=== LeftClick 1 '===以上是按键精灵录制的内容=== End If

按键精灵后台鼠标单击
VBS scy=scy+sch Plugin Msg.ShowScrTXT(zbx+24,scy,ScreenW,ScreenH, "鼠标屏幕坐标:"&sbpmx&","&sbpmy&" ", "FF0000")VBS scy=scy+sch Plugin Msg.ShowScrTXT(zbx+24, scy,ScreenW,ScreenH, "鼠标窗口坐标:"&sbckx&","&sbcky&" ", "FF0000")VBS scy=scy+sch Plugin Msg...

按键精灵中区域找图找到图片坐标后如何让鼠标点击坐标位置??
vbscall getcursorpos(x,y)rem s moveto x,y leftclick 1 goto s 脚本~运行时把鼠标发到你以后要点的那个地方

怎么获取指定句柄窗口的里面任意点的坐标
VBSCall GetCursorPos(x,y) 得到当前鼠标位置x,y Plugin Window.Move(a, x, y)把窗口a移动到x,y位置这样就不用担心窗口移动造成的点不到血条了。秘诀在于。窗口左上角坐标是x,y那么你血条坐标就可以用x+,y+ 形式表达出来。也就是用X,Y为顶点。凭借这个坐标来确定屏幕上血条的相对坐标。这样...

按键精灵:当鼠标变成变红色自动单击左键怎么编辑?
Rem 3 VBSCall FindColorEx(175,324,300,736,"0000B0",1,0.9,X,Y)If x>=0 and y>=0 Delay 1000 MoveTo X,Y LeftClick 1 Else Goto 3 EndIf 这是一个例子,其中:174,324为找范围的左上角坐标,300,736为右下角。0000B0为你要查找的颜色,希望对你有帮助 ...

怎么利用按键精灵将指定窗口移动到指定坐标上
y位置这样就不用担心窗口移动造成的点不到血条了。秘诀在于。窗口左上角坐标是x,y那么你血条坐标就可以用x+,y+ 形式表达出来。也就是用X,Y为顶点。凭借这个坐标来确定屏幕上血条的相对坐标。这样如果窗口有移动之需要重新运行一次脚本。X,Y坐标就重新确定了。不知道你听懂了没 - - ...

bat或vbs命令可以实现自定义或者更改鼠标指针样式吗?或者移动到某个地方...
鼠标指针的样式要通过控制面板(GodMode)来更改 进入GodMode方法如下,新建一个文件夹,文件名改成.{ED7BA470-8E54-465E-825C-99712043E01C}就可以了,这个文件夹就是GodMode (你直接复制就行,连上前面那个点.)

相似回答