Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I cant bring my idea to work, please take 2 minutes and answer my question.
Here's the code;

VB
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
Comments
Sergey Alexandrovich Kryukov 15-May-12 17:37pm    
Did you forget to ask your question?
--SA

1 solution

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
 
Share this answer
 
v2
Comments
Maciej Los 16-May-12 1:53am    
+5!
Sergey Alexandrovich Kryukov 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
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900