1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

How can I simulate a left button mouse click?

Discussion in 'Software Development' started by bradle95, Oct 4, 2005.

Thread Status:
Not open for further replies.
Advertisement
  1. bradle95

    bradle95 Thread Starter

    Joined:
    Jul 27, 2003
    Messages:
    46
    How can I simulate a left button mouse click without specifying the handle of the button that it is clicking. The following works if I want to simulate a click on the command1 button.

    y = SendMessage(command1.hwnd, WM_LBUTTONDOWN, 0, ByVal 0&)
    x = SendMessage(command1.hwnd, WM_LBUTTONUP, 0, ByVal 0&)

    However, I am using the SetCursorPos api, and I would just like to send a mouse down/up command to click at the point that I specify. How can I do this?
     
  2. aewarnick

    aewarnick

    Joined:
    Sep 3, 2002
    Messages:
    828
    I'm pretty sure that windows uses SendMessage to send a mouse click. SendMessage is your best choice. You can still use SetCursorPos and then send the mouse down message then a mouse up.
     
  3. IMM

    IMM Malware Specialist

    Joined:
    Feb 1, 2002
    Messages:
    3,257
  4. bradle95

    bradle95 Thread Starter

    Joined:
    Jul 27, 2003
    Messages:
    46
    I ended up finding a mouseevent api that works jut the way I needed.

    On a whole other topic, any idea how I can set multiple hotkeys for one form. I would like to be able to hit something like control F1 to do one thing, control F2 to do another... without my form having focus. I found code for a createhotkey module, but it only works if I create one hotkey, if I have more than one the form immediately closes as soon as I run it. No error or anything, it just closes.
     
  5. aewarnick

    aewarnick

    Joined:
    Sep 3, 2002
    Messages:
    828
    You can make as many hotkeys as you need. But you should post another thread for that question.
     
  6. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Hi bradle95,

    Just out of curiosity, what mouseevent api did you find, and where can one get it?

    -- Tom
     
  7. IMM

    IMM Malware Specialist

    Joined:
    Feb 1, 2002
    Messages:
    3,257
  8. bradle95

    bradle95 Thread Starter

    Joined:
    Jul 27, 2003
    Messages:
    46
    I have used several api's for this project including:

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wmsg As Long, ByVal wParam As Long, lParam As Any) As Long
    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)
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpclassname As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, _
    ByVal ID As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long

    Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, _
    ByVal ID As Long) As Long

    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long






    I'm not really sure where I got them, I just scoured the web for examples, and massaged them to fit my application.
     
  9. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/404533

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice