possible to send mouse clicks with vbs?

I know it's possible to sendkeys with vbs, is it possible to send mouse commands such as a right click? If possible what would be the statement? thanks
steve44Asked:
Who is Participating?
 
BurbbleCommented:
Here's a module I use for such a thing (it's perhaps a bit overcomplex, but it gets the job done):



Declare Function GetCursorPos& Lib "user32" (lpPoint As PointAPI)
Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
'Declare Sub Click Lib "user32" (ByVal dwFlags As Long, ByVal DX As Long, ByVal dy As Long, ByVal cbuttons As Long, ByVal dwExtraInfo As Long)
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)

Type PointAPI
X As Long
Y As Long
End Type

Public Const MOUSEEVENTF_ABSOLUTE = &H8000
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20
Public Const MOUSEEVENTF_MIDDLEUP = &H40
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10
Public Const MOUSEEVENTF_MOVE = &H1

Sub MoveMouse(X As Long, Y As Long)
    Dim SetCur As Long
    SetCur = SetCursorPos(X, Y)
End Sub

Sub LClick()
    LClick1
    LClick2
End Sub

Sub RClick()
    RClick1
    RClick2
End Sub

Sub LClick1()
    Dim CurPos
    Dim Point1 As PointAPI
    CurPos = GetCursorPos(Point1)
    mouse_event MOUSEEVENTF_LEFTDOWN, Point1.X, Point1.Y, 0, 0
End Sub

Sub RClick1()
    Dim CurPos
    Dim Point1 As PointAPI
    CurPos = GetCursorPos(Point1)
    mouse_event MOUSEEVENTF_RIGHTDOWN, Point1.X, Point1.Y, 0, 0
End Sub

Sub LClick2()
    Dim CurPos
    Dim Point1 As PointAPI
    CurPos = GetCursorPos(Point1)
    mouse_event MOUSEEVENTF_LEFTUP, Point1.X, Point1.Y, 0, 0
End Sub

Sub RClick2()
    Dim CurPos
    Dim Point1 As PointAPI
    CurPos = GetCursorPos(Point1)
    mouse_event MOUSEEVENTF_RIGHTUP, Point1.X, Point1.Y, 0, 0
End Sub
0
 
edwardiiiCommented:
Hi, steve44.

One of the answers at this EE post works for me:
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20903665.html

'Comment from TheKenman
'Date: 03/02/2004 04:55AM PST  


'Right click = onContextMenu.

<html>
<head>
<SCRIPT language="VBScript">
Function rClicky()
       window.event.returnValue = false
       rClicky = msgbox("No r-clicky!!")
End Function
</SCRIPT>
</head>
<body onContextMenu="rClicky()">
right-clicky anywhere...
</body>
</html>
0
 
BurbbleCommented:
Whooops VB *Script*  :)
0
 
edwardiiiCommented:
Hi, steve44.

How did you get Burbble's code to work with VB Script?
0
 
BurbbleCommented:
Maybe he meant VBA?

Hmm
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.