Is it possible to drive a mouse out of a vb-application?
- mouse moving over the screen
- clicking
Is it possible to drive a mouse out of a vb-application?
- mouse moving over the screen
- clicking
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
Insomnia is just a byproduct of, "It can't be done"
Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
Here is the list of TAGs you can use to format your posts
{Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
{VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}
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?
try this:
do this form
then write this in the form:
then add a module and write this: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)
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
Herbie
Regarding getting and setting the cursor position
by code, something like this ..
In declarations
In a sub .. (I just grabbed one I had .. modify as req'd)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
SpooCode: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