NdNoviceHlp
Well-known Member
- Joined
- Nov 9, 2002
- Messages
- 3,721
The objective is to identify and store a pointer location, then return to it by a macro call. TsTom has provided the get and DK(Dan) has provided the move to that location (thanks plenty!). I can't seem to combine this help to achieve my objective. Please help. Thanks.
' TsTom to get pointer location
Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Dim z As POINTAPI ' Declare variable
Sub mouscoords()
GetCursorPos z
'MsgBox "Your cursor is located at: X," & z.x & " Y," & z.y (I don't need this part)
End Sub
' DK(Dan) to move pointer to location
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Sub SetMousePosition(x As Long, y As Long)
'This next line makes sure that the specified coordinates are valid.
'If you try and call an API call with invalid arguments you could cause your
'system to crash. You will need to adjust this line to take account of different
'screen resolutions. You could be clever and use the GetSystemMetrics API call to
'automatically adjust for different resolution.
'If x < 0 Or x > 1024 Or y < 0 Or y > 768
Then Exit Sub (I don't think I need this part?)
SetCursorPos x, y
end sub
' TsTom to get pointer location
Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Dim z As POINTAPI ' Declare variable
Sub mouscoords()
GetCursorPos z
'MsgBox "Your cursor is located at: X," & z.x & " Y," & z.y (I don't need this part)
End Sub
' DK(Dan) to move pointer to location
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Sub SetMousePosition(x As Long, y As Long)
'This next line makes sure that the specified coordinates are valid.
'If you try and call an API call with invalid arguments you could cause your
'system to crash. You will need to adjust this line to take account of different
'screen resolutions. You could be clever and use the GetSystemMetrics API call to
'automatically adjust for different resolution.
'If x < 0 Or x > 1024 Or y < 0 Or y > 768
Then Exit Sub (I don't think I need this part?)
SetCursorPos x, y
end sub