-
Feb 22nd, 2012, 01:52 PM
#1
Thread Starter
New Member
Moving a mouse by application driven
Is it possible to drive a mouse out of a vb-application?
- mouse moving over the screen
- clicking
-
Feb 22nd, 2012, 02:32 PM
#2
Re: Moving a mouse by application driven
Welcome to the forums
I think you will have to give much more information/details. I, for one, cannot determine what you are asking. Too general
Suggest taking a few minutes and reading the Hitchhiker's Guide, linked in my signature below
-
Feb 22nd, 2012, 03:21 PM
#3
Addicted Member
Re: Moving a mouse by application driven
Sounds like he wants to use a vb app to hook the mouse and auto control it over the screen and auto click it, taking control away from the user. The question is ...Why?
-
Feb 22nd, 2012, 05:46 PM
#4
New Member
Re: Moving a mouse by application driven
try this:
do this form
then write this in the form:
Code:
Dim k
Private Sub Command1_Click()
Call mouse_event(MOUSEEVENTF_MOVE, -k, 0, 0, 0)
End Sub
Private Sub Command2_Click()
Call mouse_event(MOUSEEVENTF_MOVE, 0, -k, 0, 0)
End Sub
Private Sub Command3_Click()
Call mouse_event(MOUSEEVENTF_MOVE, k, 0, 0, 0)
End Sub
Private Sub Command4_Click()
Call mouse_event(MOUSEEVENTF_MOVE, 0, k, 0, 0)
End Sub
Private Sub Command5_Click()
Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
Private Sub Command6_Click()
Call mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
Call mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
End Sub
Private Sub Command7_Click()
Call mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0)
Call mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0)
End Sub
Private Sub Form_Load()
k = 4
'greater k will result in more amount of movment of the pointer
End Sub
'You can also use mouse wheel using this:
'd is the amout of movement
'positive d goes up and negative d goes down
'd=120
'Call mouse_event(MOUSEEVENTF_WHEEL, 0, 0, d, 0)
then add a module and write this:
Code:
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 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Public Const MOUSEEVENTF_MOVE = &H1
Public Const MOUSEEVENTF_MOUSEEVENTF_ABSOLUTE = &H8000
Public Const MOUSEEVENTF_WHEEL = &H800
-
Feb 22nd, 2012, 09:34 PM
#5
Re: Moving a mouse by application driven
Herbie
Regarding getting and setting the cursor position
by code, something like this ..
In declarations
Code:
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
In a sub .. (I just grabbed one I had .. modify as req'd)
Code:
Public Sub CurXbaby(cWhat, nZ1)
'
Dim CurPos As POINTAPI
Dim PosX As Long, PosY As Long
Dim pp As Long
GetCursorPos CurPos
PosX = CurPos.x
PosY = CurPos.y
'
If cWhat = "show" Then
SetCursorPos PosX - nZ1, PosY
ElseIf cWhat = "reset" Then
SetCursorPos PosX + nZ1, PosY
End If
'
End Sub
Spoo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|