Results 1 to 4 of 4

Thread: Emulate Left Mouse Button

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2001
    Posts
    2

    Unhappy

    This is for a school project. I'm building a program that receives a number from the serial port. If that number is number 4, for example, it simulates the left mouse button. So, if the mouse is over a command button, and the serial port receives the number 4, the command button will be selected (activated), as if it was clicked with the mouse. So far, all I can do is receiving that number from the serial port, through a microcontroller. The number is well sent to the PC, I've tested it. So far so good. What I can't do is simulating the mouse click, the left button. I've searched through Visual Basic 6.0 help, but can't figure out what to do! Should I use an API?? Can someone help me?? Thank you.

    P.S.: Here is my program. The toggle button is to open/close the serial port. I'm reading the buffer from the serial port in a text box (more simple). Then I compare it to number 4. If it's true, how do I simulate the mouse click?? It will help if someone knows how to simulate if number 4 is pressed from keyboard, for example. The objective is to simulate the left mouse button...without using the mouse!!
    Attached Files Attached Files

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    'Before you start this program, I suggest you save everything that wasn't saved yet.
    Private 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)
    Const MOUSEEVENTF_LEFTDOWN = &H2
    Const MOUSEEVENTF_LEFTUP = &H4
    Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Const MOUSEEVENTF_MIDDLEUP = &H40
    Const MOUSEEVENTF_MOVE = &H1
    Const MOUSEEVENTF_ABSOLUTE = &H8000
    Const MOUSEEVENTF_RIGHTDOWN = &H8
    Const MOUSEEVENTF_RIGHTUP = &H10
    Private Sub Form_Activate()
        Do
            'Simulate a mouseclick on the cursor's position
            mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0&, 0&, cButt, dwEI
            DoEvents
        Loop
    End Sub
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Guest
    Code:
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    
    Private Sub Command1_Click()
        PostMessage mybutton.hwnd, WM_LBUTTONDOWN, 1, 0
        PostMessage mybutton.hwnd, WM_LBUTTONUP, 1, 0
    End Sub

  4. #4
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    it shouldn't be too hard:

    Code:
    'Before you start this program, I suggest you save everything that wasn't saved yet.
    Private 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)
    Const MOUSEEVENTF_LEFTDOWN = &H2
    Const MOUSEEVENTF_LEFTUP = &H4
    Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Const MOUSEEVENTF_MIDDLEUP = &H40
    Const MOUSEEVENTF_MOVE = &H1
    Const MOUSEEVENTF_ABSOLUTE = &H8000
    Const MOUSEEVENTF_RIGHTDOWN = &H8
    Const MOUSEEVENTF_RIGHTUP = &H10
    Private Sub Form_Activate()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Do
            'Simulate a mouseclick On the cursor's position
            mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0&, 0&, cButt, dwEI
            DoEvents
        Loop
    End Sub
    Modify it to fit your needs.
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

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