Click here to Skip to main content
15,897,226 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionProgrammatically controlling mouse. Pin
the fossil31-Jan-09 1:42
the fossil31-Jan-09 1:42 
AnswerRe: Programmatically controlling mouse. Pin
Dave Kreskowiak31-Jan-09 16:23
mveDave Kreskowiak31-Jan-09 16:23 
GeneralRe: Programmatically controlling mouse. Pin
the fossil1-Feb-09 4:02
the fossil1-Feb-09 4:02 
GeneralRe: Programmatically controlling mouse. Pin
Dave Kreskowiak1-Feb-09 6:36
mveDave Kreskowiak1-Feb-09 6:36 
GeneralRe: Programmatically controlling mouse. Pin
the fossil1-Feb-09 7:16
the fossil1-Feb-09 7:16 
GeneralRe: Programmatically controlling mouse. Pin
Dave Kreskowiak1-Feb-09 11:20
mveDave Kreskowiak1-Feb-09 11:20 
AnswerRe: Programmatically controlling mouse. Partial answer Pin
the fossil2-Feb-09 9:25
the fossil2-Feb-09 9:25 
AnswerRe: Programmatically controlling mouse. Pin
Bharat Jain2-Feb-09 20:50
Bharat Jain2-Feb-09 20:50 
Hi Steve,
You are right , you can use mouse_even API to control the mouse movements , you can use the same API to control the click and scroll of the mouse ,following is an example to show you the use of this API

You don't require to write a device driver for it Smile | :)

I was try to answer this thread long , but got some error while posting , then it skipped of my mind Smile | :)
Sorry for that

This is the example to move the mouse

Public Class Form1
    Declare Auto Function mouse_event Lib "user32.dll" (ByVal dwflags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal dwData As Integer, ByVal dwExtraInfo As Integer) As Integer
    Const MOUSEEVENTF_MOVE As Int32 = &H1 '  mouse move
    Const MOUSEEVENTF_LEFTDOWN As Int32 = &H2 '  left button down
    Const MOUSEEVENTF_LEFTUP As Int32 = &H4 '  left button up
    Const MOUSEEVENTF_RIGHTDOWN As Int32 = &H8 '  right button down
    Const MOUSEEVENTF_RIGHTUP As Int32 = &H10 '  right button up
    Const MOUSEEVENTF_MIDDLEDOWN As Int32 = &H20 '  middle button down
    Const MOUSEEVENTF_MIDDLEUP As Int32 = &H40 '  middle button up
    Const MOUSEEVENTF_ABSOLUTE As Int32 = &H8000 '  absolute move
    Const MOUSEEVENTF_WHEEL As Int32 = &H800 ' wheel button rolled
    Dim x As Int32 = 50
    Dim y As Int32 = 50
    Dim multiPlyfactorX = 65535 / Screen.PrimaryScreen.WorkingArea.Width
    Dim multiPlyfactory = 65535 / Screen.PrimaryScreen.WorkingArea.Height

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        mouse_event(MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE, x * multiPlyfactorX, y * multiPlyfactory, 0, 0)
        x = x + 1
        y = y + 1
    End Sub
End Class


Here you would have noticed that i have used two variable called multiPlyfactorX , multiPlyfactory. This is because the API takes 0,0 as left-top corner and 65535,65535 as right-bottom corner

also to send a click you can use the following code

mouse_event(MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, x * multiPlyfactorX, y * multiPlyfactory, 0, 0)


Here x,y are the co-ordinates in pixcels

I hope this helps !!
I have to move now , let me know if you need any other help / information

-Regards
Bharat Jain
bharat.jain.nagpur@gmail.com

GeneralRe: Programmatically controlling mouse. Pin
the fossil2-Feb-09 22:51
the fossil2-Feb-09 22:51 
GeneralRe: Programmatically controlling mouse. Pin
Bharat Jain2-Feb-09 23:51
Bharat Jain2-Feb-09 23:51 
GeneralRe: Programmatically controlling mouse. Pin
the fossil3-Feb-09 3:25
the fossil3-Feb-09 3:25 
GeneralRe: Programmatically controlling mouse. Pin
the fossil3-Feb-09 3:40
the fossil3-Feb-09 3:40 
GeneralRe: Programmatically controlling mouse. Pin
the fossil3-Feb-09 3:44
the fossil3-Feb-09 3:44 
QuestionCreating DataTable from System.Collections.Generic.List Pin
kanchoette31-Jan-09 1:23
kanchoette31-Jan-09 1:23 
AnswerRe: Creating DataTable from System.Collections.Generic.List Pin
Wendelius31-Jan-09 1:56
mentorWendelius31-Jan-09 1:56 
GeneralRe: Creating DataTable from System.Collections.Generic.List Pin
kanchoette31-Jan-09 2:05
kanchoette31-Jan-09 2:05 
GeneralRe: Creating DataTable from System.Collections.Generic.List Pin
Wendelius31-Jan-09 2:26
mentorWendelius31-Jan-09 2:26 
GeneralRe: Creating DataTable from System.Collections.Generic.List Pin
kanchoette31-Jan-09 3:10
kanchoette31-Jan-09 3:10 
GeneralRe: Creating DataTable from System.Collections.Generic.List Pin
Wendelius31-Jan-09 3:17
mentorWendelius31-Jan-09 3:17 
QuestionEdit Vista file properties details with VBA Pin
piralko30-Jan-09 22:38
piralko30-Jan-09 22:38 
QuestionPopulating from one combobox to another combobox in VB.NET [modified] Pin
kishore1530-Jan-09 20:06
kishore1530-Jan-09 20:06 
AnswerRe: Populating from one combobox to another combobox in VB.NET Pin
Christian Graus30-Jan-09 20:23
protectorChristian Graus30-Jan-09 20:23 
QuestionUnable to close or kill the Excel Application EXE in the Task Manager through code. Pin
manoharbalu30-Jan-09 18:35
manoharbalu30-Jan-09 18:35 
AnswerRe: Unable to close or kill the Excel Application EXE in the Task Manager through code. Pin
Dave Kreskowiak31-Jan-09 4:22
mveDave Kreskowiak31-Jan-09 4:22 
Questionhelp file creation Pin
ngugi30-Jan-09 5:36
ngugi30-Jan-09 5:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.