我需要從VBS發送鼠標點擊。像SendKeys一樣。我搜索了整個谷歌,似乎VBS沒有這樣的功能。你能給我一些解決方案嗎?VBS發送鼠標點擊?
2
A
回答
0
嘗試
Dim x
set x=createobject("wscript.shell")
x.sendkeys"{CLICK LEFT,50,60}"
或
x.SendKeys("+{F10}") 'for a right click
如果沒有適合你的工作,我會建議使用像Autoit或autohotkey,使用AutoHotkey的,你可以寫一個宏,做的點擊,然後的從你的VBScript調用腳本。
0
單獨使用VBScript是不可能的。您需要使用第三方工具,如nircmd。您可以使用它的setcursor
,setcursorwin
,movecursor
和sendmouse
命令來操縱鼠標。
例如,這裏是如何將光標移動到屏幕座標(自左上角測量)並執行右鍵單擊:
With CreateObject("WScript.Shell")
.Run "nircmd setcursor 100 100", 0, True
.Run "nircmd sendmouse right click", 0, True
End With
的參數信息,請參閱documentation。
3
這是一個在VBA for Excel中向窗口(使用相對引用)發送左鍵或右鍵單擊的例程。與AppActivate類似,您只需要窗口標題。
的參數,當調用SendClick程序是:
- 窗口標題(字符串)
- 按鈕(1 =左,2 =右,-1 =移動鼠標只;沒有點擊)
- X(相對位置窗口左)
- Y(相對位置窗口頂部)
享受!
'Declare mouse events
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public 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)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
'Declare sleep
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' Window location
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Function WindowHandle(ByVal sTitle As String) As Long
WindowHandle = FindWindow(vbNullString, sTitle)
End Function
Public Sub SendClick(sWnd As String, b As Integer, x As Long, y As Long)
Dim pWnd As Long, pRec As RECT
pWnd = WindowHandle(sWnd)
GetWindowRect pWnd, pRec
SetCursorPos pRec.Left + x, pRec.Top + y
Sleep 50
If b = 2 Then
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
Sleep 50
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
ElseIf b <> -1 Then
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 50
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End If
End Sub
相關問題
- 1. 鼠標左鍵點擊vbs
- 2. 發送鼠標點擊
- 3. 模仿鼠標點擊的vbs腳本
- 4. 如何發送鼠標點擊?
- 5. 發送鼠標點擊從Flash到JS
- 6. Python Xlib捕獲/發送鼠標點擊
- 7. 通過發送消息單擊鼠標
- 8. 發送鼠標單擊特定位置而不移動鼠標
- 9. SDL鼠標點擊
- 10. Powershell,鼠標點擊
- 11. SeaDragon鼠標點擊
- 12. 鼠標點擊JTable
- 13. 鼠標點擊java
- 14. 鼠標點擊jquery
- 15. 鼠標點擊向我發送消息多次在C++
- 16. C++:使用PostMessage/SendMessage發送鼠標點擊
- 17. 如何在PowerShell中發送鼠標點擊
- 18. 電源外殼:如何發送鼠標中鍵點擊?
- 19. 發送由GetAsyncKeyState()忽略的虛擬鼠標點擊?
- 20. 在.net中發送鼠標點擊消息
- 21. 如何將鼠標點擊事件發送到隱藏窗口?
- 22. 什麼會導致PostMessage發送的鼠標點擊被忽略?
- 23. 試圖發送鼠標點擊遊戲窗口,mac
- 24. 點擊事件防止鼠標觸發
- 25. 鼠標點擊原點
- 26. 繪圖點鼠標點擊
- 27. 讓鼠標在鼠標點擊鼠標後跟着鼠標
- 28. 鼠標點擊標籤
- 29. CodedUi:鼠標點擊座標
- 30. 多個鼠標事件在點擊鼠標時觸發