Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET API Mouse
I cant bring my idea to work, please take 2 minutes and answer my question.
Here's the code;
 
Public Class Form1
    Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Integer
    Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Integer
 
    Private Declare Sub mouse_event Lib "user32" Alias "mouse_event" _
        (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, _
         ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
 
    Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
    Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
    Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
    Private Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Private Const MOUSEEVENTF_MIDDLEUP = &H40
    Private Const MOUSEEVENTF_RIGHTDOWN = &H8
    Private Const MOUSEEVENTF_RIGHTUP = &H10
    Private Const MOUSEEVENTF_WHEEL = &H20A
 
    Private Sub mouseCommands
 
        ' Wheel Rotation Forward 
        ' ??????????

        ' Wheel Rotation Backward
        ' ??????????

        ' Left Mouse-DoubleClick
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) ' Button Press
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) ' Button Release
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) ' Button Press
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) ' Button Release

        ' Left Mouseclick
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
 
        ' Right Mouseclick
        mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
        mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
 
        ' Middle Click
        mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0)
        mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0)
 
        ' Set Mouse Cursor to a specific position
        SetCursorPos(300, 400)
 
        ' Drag and drop
        SetCursorPos(300, 400) ' Where your desired file is located at(screenheight, screenwidth)
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
        SetCursorPos(500, 500) ' Where to release file, respectively the button
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    End Sub
Posted 15-May-12 11:30am
Comments
SAKryukov at 15-May-12 17:37pm
   
Did you forget to ask your question?
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Just one advice: mouse_event was superseded with newer function SendInput: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].
 
Use it.
 
If works; wheel events can be used, which is described here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646273%28v=vs.85%29.aspx[^].
 
The P/Invoke version is already written for you, courtesy of PInvoke.NET:
http://www.pinvoke.net/default.aspx/user32.sendinput[^].
 
—SA
  Permalink  
v2
Comments
losmac at 16-May-12 1:53am
   
+5!
SAKryukov at 16-May-12 11:34am
   
Thank you,
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 290
1 Jochen Arndt 165
2 DamithSL 125
3 PIEBALDconsult 110
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 15 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100