Results 1 to 13 of 13

Thread: Mouse Up/Down [RESOLVED]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    16

    Mouse Up/Down [RESOLVED]

    i am trying to figure out how to make a program to detect if a left or right mouse button has been pressed using a VB6 application that is hidden. does anyone know if this is even possible using vb6? im new at programming so im not sure where to even start. thanks guys
    Last edited by RhythmMike; Apr 13th, 2004 at 03:00 PM.

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    Not sure what you mean by "hidden application", but here's one in the code itself:

    VB Code:
    1. Private Sub Form1_MouseDown() 'don't remember what goes in here
    2.  
    3.    If vbRightButton Then
    4.       'whatever happens if right button is hit
    5.    ElseIf vbLeftButton Then
    6.       'whatever happens if left button is hit
    7.    Else
    8.       'whatever happens if middle button is hit
    9.    End If
    10.  
    11. End Sub

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    You can use GetAsyncKeyState to check wheather or not the mouse is down...

    VB Code:
    1. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    2.  
    3. Private Sub Timer1_Timer()
    4. Dim Ret As Integer
    5. Ret = GetAsyncKeyState(1) 'vbKeyLButton = 1
    6. MsgBox Ret
    7. End Sub

    If it is less than 1 the mouse button is down..

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    16
    thanks guys! what i mean by hidden is like if the application is minimized and another is in focus

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Thats what my code does...look.. you'll have to press stop in the VB IDE to stop the program..

    Phreak
    Attached Files Attached Files

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    16
    thats exactly what i have been looking for! thanks soo much! now im wondering... is there anyway that it will record only when you press the middle mouse button?

  7. #7
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Change the GetAsyncKeyState(1) to GetAsyncKeyState(4)

    Left Mouse Button = 1
    Middle Mouse Button = 4
    Right Mouse Button = 2



    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    16
    hmmm... i changed it to this:

    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Dim file_contents As String
    
    Private Sub Timer1_Timer()
    Dim Ret As Integer
    Ret = GetAsyncKeyState(1) 'vbKeyLButton = 1
    If Ret < 1 Then
        Text1.Text = Text1.Text + 1
        
        
        
    End If
    End Sub
    i added a text box to show every time it is clicked but for some reason the text box just keep going up whether i click or not.. i then changed it to If Ret = 1 Then and with that you have to click the mouse a few times before it adds one to the text. anyone know whats goin on?

  9. #9
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Its the Timer's Interval. You need to try and get it to the right one. It has to be close to the human reaction time for clicking a mouse. You just need to experiment with it, changing the Timer's interval property to lower values.

    EDIT:
    And you should keep it
    VB Code:
    1. If Ret < 1 Then

    If it is < 1 it means the mouse is DOWN. If it is 1, it means the mouse is UP...


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    16
    i dont understand what you mean.. using that code i was thinking that everytime you click it would add +1.. using the timer and when Ret < 1 it only adds +1 once the timer runs down

  11. #11
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Ok, this is what the code does.

    Once (1 time) a second, the program checks if the Mouse is DOWN (Ret < 1). If it IS down, it writes to the file (your program adds to a textbox). If it ISN'T down (Ret = 1) then it does nothing. The timer will continue to execute that code Once (1 time) per second, until the program is closed..

    EDIT:
    Also, the Mouse MUST be down at the exact time the timer executes that code, which is why you need to put it to a smaller value than Once a second.

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    16
    ok i understand it now.. thank you! now im wondering... is there a way to make the timer less than 1? i have it so that when you hold down the button it adds +1 each time the timer counts down from 1, but i want it a faster.. i know i didnt explain it very well

    what fraction of a second is 1 in the vb timer?

  13. #13
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    1000 = 1 second

    1 = 1/1000th of a second..


    Why do you need it faster than that?


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width