+ Reply to Thread
Results 1 to 5 of 5

Mouse_event click

Hybrid View

  1. #1
    Registered User
    Join Date
    08-01-2020
    Location
    Paris
    MS-Off Ver
    2016
    Posts
    17

    Mouse_event click

    Hello,
    I'am beginner in VBA and I need some help please.
    I try to handle an external application with vba macro, and actually I need to push a button on this application. The application name is Axel, and I am traying to do this with mouse_event, so the idea is to postion the cursor on the right button then launch a mouse-event leftdown and leftup. But the problem is that the click is happened before that application is opened on the screen so it clicks somewhere else on the screen. Can you please give a help?
    This is my code:

    Option Explicit
    Private Declare Function GetDesktopWindow Lib "User32" () As Long
    Private Declare Function GetWindow& Lib "User32" (ByVal hWnd&, ByVal wCmd&)
    Private Declare Function GetWindowLong& Lib "User32" _
    Alias "GetWindowLongA" (ByVal hWnd&, ByVal nIndex&)
    Private Declare Function GetWindowText& Lib "User32" Alias _
    "GetWindowTextA" (ByVal hWnd&, ByVal lpString$, ByVal aint&)
    Private Const mconMAXLEN = 255
    
    
    Public Declare Function SetCursorPos Lib "User32" (ByVal x As Long, ByVal y As Long) As Long
    Public 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)
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Public Const MOUSEEVENTF_LEFTDOWN = &H2
    Public Const MOUSEEVENTF_LEFTUP = &H4
    Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
    Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
    
    Sub AxelActivate()
    
    Dim hWnd&, Style&, Title$, i&
    Dim Nom As String
    Dim hWndApp, hWndButton As Long
    
    hWnd = GetWindow(GetDesktopWindow(), 5)
    
    Do While hWnd
    Title = GetCaption(hWnd)
    If Len(Title) Then
    
        If GetWindowLong(hWnd, -16) And &H10000000 Then
            If InStr(1, Title, "Axel", 1) Then
            AppActivate Title
            SendKeys "~"
            Exit Sub
            End If
        End If
    End If
    
    
    hWnd = GetWindow(hWnd, 2)
    
    
    SetCursorPos 60, 200 'x and y position
    
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
    
    
    Loop
    
    
    MsgBox "Axel is not opened!", vbCritical, "ERROR"
    
    End Sub
    
    Private Function GetCaption(hWnd&) As String
    Dim i%, Buffer$: Buffer = String$(254, 0)
    i = GetWindowText(hWnd, Buffer, 255)
    If i Then GetCaption = Left$(Buffer, i)
    End Function
    Also if someone has an other idea to click on a button with only vba It will be a great thing.

    Thank you

  2. #2
    Registered User
    Join Date
    08-01-2020
    Location
    Paris
    MS-Off Ver
    2016
    Posts
    17

    Re: Mouse_event click

    I tried sleep and wait.application method, but it's not working such the instructions are inside a loop.

  3. #3
    Registered User
    Join Date
    08-01-2020
    Location
    Paris
    MS-Off Ver
    2016
    Posts
    17

    Re: Mouse_event click

    No idea to overcome this problem? I'm still blocked

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,018

    Re: Mouse_event click

    .
    60 views and no replies.

    Your opportunities for assistance will be few ... the wait will be long.

    Some things pertinent to the discussion : What is Axel ? Where can one see an operating version of one ? Have you contacted the company that produces Axel, for assistance ?

  5. #5
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Mouse_event click

    if you need to simulate a click use AutoHotkey not Excel

    you need to learn to write the code to wait for the window to appear then position the mouse pointer then simulate the click
    they have a forum also i believe

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] doble click to modify selected record in listbox and right click to delete
    By bluepomme in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-08-2019, 08:43 PM
  2. Click -Select File -Sort-Copy-Paste into the master report in one click (Help Please)
    By spider_min in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-22-2018, 01:08 AM
  3. [SOLVED] make button single click to avoid user double click
    By Muzza1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2016, 01:02 AM
  4. [SOLVED] ActiveX combobox click triggers unwanted another comboxbox click event
    By aprildu in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-12-2015, 10:08 AM
  5. A macro to right click a cell and select a item from the right click menu?
    By Peavey in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-13-2014, 10:55 AM
  6. Replies: 0
    Last Post: 03-06-2013, 12:52 PM
  7. Replies: 4
    Last Post: 08-02-2005, 09:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1