Results 1 to 11 of 11

Thread: how do i send/post a click inside another program?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    17

    Post

    how do i send/post a click inside another program?
    if it's minmized? i know it's handle and the pos i want to click in the program
    how should i do?

    thanks for answering questions like these over and over again


    thanks in advance, and as always help is appreciated.

  2. #2
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210
    Code:
    Declare Function SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal 
    wMsg As Long, ByVal wParam As Long, lParam As Any)
    Const VK_SPACE = &H20
    Const WM_KEYUP = &H101
    Const WM_KEYDOWN = &H100
    Sub Click_Button(Handle As Long)
    Call SendMessage(Handle&, WM_KEYDOWN, VK_SPACE, vbNullString)
    Call SendMessage(Handle&, WM_KEYUP, VK_SPACE, vbNullString)
    End Sub
    Just call that sub and it'll click the button. I'm pretty sure it'll work if it's minimized
    < o >

  3. #3
    Megatron
    Guest
    No, that wont work, since SendMessage will always wait for a return value rather than return immediately. In this case, you need to use PostMessage instead.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    17

    but how does it know where to click?

    but how does it know where to click?

    dont i need to declare the coords for the click inside the prog.?

  5. #5
    Megatron
    Guest
    The LoWord of lParam specfies the X-coordinates, and the HiWord of lParam specfies the Y-coordinates.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    17

    ooh :)

    k

  7. #7
    Megatron
    Guest
    Since VB, doesn't come with any sort of MakeDWORD function, here it is:
    Code:
    Public Function MakeWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
       MakeWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
    End Function
    Usage
    Code:
    Dword = MakeWord ( LoWord, HiWord )

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    17

    thx

    thx for clearing that.. (for like 1 min ago i searched www.freevbcode.com) trying to find something like that but i wasn't sure what i was looking for, so thx for clearing it up!

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Posts
    17

    can't get it to work

    i tried:

    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 Const MK_LBUTTON = &H1

    Private Sub Command1_Click

    Dword = MakeWord (54, 456)

    PostMessage hWndOfwindow, WM_LBUTTONDOWN, MK_LBUTTON, Dword
    PostMessage hWndOfwindow, WM_LBUTTONUP, MK_LBUTTON, Dword
    End Sub

    ****

    i couldn't get that to work, it just doesn't click, recenlty i found:
    Public Function IntegersToLong(LoWord As Integer, _
    HiWord As Integer) As Long

    IntegersToLong = (HiWord * &H10000) + (LoWord And &HFFFF&)

    End Function

    but i haven't tested it, maybe that's the solution?

  10. #10
    Megatron
    Guest
    Yes, that is the correct method (mine used Or instead of "+" ).

  11. #11
    Megatron
    Guest
    Actually, Or and + are the same so this should work
    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 Const MK_LBUTTON = &H1
    
    Public Function MakeWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
       MakeWord = (HiWord * &H10000) + (LoWord And &HFFFF&)
    End Function
    
    Private Sub Command1_Click()
        dword = MakeWord(4, 4)
        PostMessage hwnd, WM_LBUTTONDOWN, 1, dword
        PostMessage hwnd, WM_LBUTTONUP, 1, dword
    End Sub
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Print X / Screen.TwipsPerPixelX & "-" & Y / Screen.TwipsPerPixelY
    End Sub

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