Chacanger
Programmer
- Feb 22, 2011
- 7
Hi
I've recently been trying to automate the mouse to do certian things in external programs as I can't actually automate them another way. I have tried to do some of this with Calculator recently but I can't seem to get the mouse to L click, hold the L click and R click.
I need to do the follwing steps so that I can use this as refference for a future idea I have in mind...
1.Open Calculator(C:\WINDOWS\system32\Calc.exe).
2.Use the mouse to move to 9 button and click it.
3.Use the mouse to move to + button and click it.
4.Use the mouse to move to 8 button and click it.
5.Use the mouse to move to = button and click it.
5.Use the mouse to move to the answer box and highlight the value ready to copy it.
Here is my code so far...
------------------------------------------------------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub test()
Dim Rec As RECT
Shell "D:\WINDOWS\system32\Calc.exe", vbMaximizedFocus
GetWindowRect GetWindowHandle, Rec
SetCursorPos Rec.Right - 135, Rec.Top + 135
SetCursorPos Rec.Right - 200, Rec.Top + 135
SetCursorPos Rec.Right - 1100, Rec.Top + 166
End Sub
Private Function GetWindowHandle() As Long
Const CLASSNAME_MSExcel = "XLMAIN"
'Gets the Apps window handle, since you can't use App.hInstance in VBA (VB Only)
GetWindowHandle = FindWindow(CLASSNAME_MSExcel, vbNullString)
End Function
------------------------------------------------------------
It will need to be with mouse as there dosen't seem to be any other plausible way of doing it. Also I can't use automation software from were I'm situated
Many Thanks
Chacanger
I've recently been trying to automate the mouse to do certian things in external programs as I can't actually automate them another way. I have tried to do some of this with Calculator recently but I can't seem to get the mouse to L click, hold the L click and R click.
I need to do the follwing steps so that I can use this as refference for a future idea I have in mind...
1.Open Calculator(C:\WINDOWS\system32\Calc.exe).
2.Use the mouse to move to 9 button and click it.
3.Use the mouse to move to + button and click it.
4.Use the mouse to move to 8 button and click it.
5.Use the mouse to move to = button and click it.
5.Use the mouse to move to the answer box and highlight the value ready to copy it.
Here is my code so far...
------------------------------------------------------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub test()
Dim Rec As RECT
Shell "D:\WINDOWS\system32\Calc.exe", vbMaximizedFocus
GetWindowRect GetWindowHandle, Rec
SetCursorPos Rec.Right - 135, Rec.Top + 135
SetCursorPos Rec.Right - 200, Rec.Top + 135
SetCursorPos Rec.Right - 1100, Rec.Top + 166
End Sub
Private Function GetWindowHandle() As Long
Const CLASSNAME_MSExcel = "XLMAIN"
'Gets the Apps window handle, since you can't use App.hInstance in VBA (VB Only)
GetWindowHandle = FindWindow(CLASSNAME_MSExcel, vbNullString)
End Function
------------------------------------------------------------
It will need to be with mouse as there dosen't seem to be any other plausible way of doing it. Also I can't use automation software from were I'm situated
Many Thanks
Chacanger