VBA left click without user32.dll; SendKeys two keys; Mousekeys with VBA?

OMGSALESFORCE2

New Member
Joined
Feb 24, 2021
Messages
24
Office Version
  1. 365
  2. 2019
  3. 2016
Is there a way to left click the mouse in VBA without using the user32.dll?

I was trying to use MouseKeys --- enabled by pressing Control Panel - searching Ease of Access at the top right - clicking Ease of Access Center - clicking Make the mouse easier to use - checking Turn on Mouse Keys.

Then when you press \ and 5 at the same time, you can left click using Mouse Keys.

I tried to use send keys with VBA and \5 to simulate a left click, but my VBA just sends the characters \5 to the browser searchbar instead of left clicking.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
See if you can make use of this utility

 
Upvote 0
VBA Code:
Option Explicit

Public Type POINTAPI
    X As Long
    Y As Long
End Type

Public Declare Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Long
Public Declare Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As POINTAPI) 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)

Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up

Private Sub Example()
    Dim CurrentPosition As POINTAPI
    
    Call GetCursorPos(CurrentPosition)
    Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
 
Upvote 0
VBA Code:
Option Explicit

Public Type POINTAPI
    X As Long
    Y As Long
End Type

Public Declare Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Long
Public Declare Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As POINTAPI) 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)

Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up

Private Sub Example()
    Dim CurrentPosition As POINTAPI
   
    Call GetCursorPos(CurrentPosition)
    Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
He was saying without using user32.dll :)
 
Upvote 0
See if you can make use of this utility

this looks promising... im just sitting here becoming hot ice cream not being able to do it
1615352216902.png
 
Upvote 0
See if you can make use of this utility

this almost looks like I can use the notepad below and maybe compile a java class in command run? no idea will gaggle with it this weekend

Dim Ret
Shell "Notepad.exe", vbNormalFocus
Ret = Shell("Path\SendKeys.exe 1 10 ""Untitled - Notepad"" ""Hello!~{PAUSE}After of 1s.~{PAUSE 2}After of 3s.~""", vbNormalFocus)
 
Upvote 0
^^^ no idea how to run a .exe also java is mad annoying the one book i tried to read on it the author went mad like 150 pages in
 
Upvote 0
^^^ no idea how to run a .exe also java is mad annoying the one book i tried to read on it the author went mad like 150 pages in
I never tried anything like this to be able to help. You are way above me :)
 
Upvote 0

Forum statistics

Threads
1,214,806
Messages
6,121,672
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top