|
Post by kevinper on Nov 25, 2021 16:25:20 GMT -5
I don't know that I will ever grasp API/DLL's. I keep reading Liberty Basic articles but nothing seems to click (no pun intended.)
I'm wondering if someone can help me simulate a mouse click. This also a project on Rosetta Code but no LB submission.
From reading different info on sites, I have started the following and really don't know if I'm close or not:
MOUSEEVENTF.LEFTDOWN = 2 ' left button down
MOUSEEVENTF.LEFTUP = 4 ' left button up
function click_mouse()
calldll #user32, "mouse_event",_
dwFlags As Long,_
dx As Long,_
dy As Long,_
cButtons As Long,_
dwExtraInfo As Long
end function
'function click()
'mouse_event(MOUSEEVENTF.LEFTDOWN, 0, 0, 0, 0)
'mouse_event(MOUSEEVENTF.LEFTUP, 0, 0, 0, 0)
'end function
end
I already have the mouse position and just want to have it left-click when my program tells it to.
Any takers?
Thanks
|
|
|
Post by Brandon Parker on Nov 25, 2021 19:46:23 GMT -5
Hello kevinper and welcome to the community! See if you can get this code to work for what you are trying to do. If not, just ask questions about it. 'Before going to the trouble of creating a variable for 'Windows constants, try printing them out first. 'If the test print code compiles then you know 'LB is "aware" of the constants and you can use 'them as shown below. Print _MOUSEEVENTF_LEFTDOWN' = 2 ' left button down Print _MOUSEEVENTF_LEFTUP' = 4 ' left button up Print _MOUSEEVENTF_ABSOLUTE Print _MOUSEEVENTF_RIGHTDOWN Print _MOUSEEVENTF_RIGHTUP
'Create a couple of X & Y variables for use (not actually required...) 'You could hard code them desiredX = 100 desiredY = 100
'Let's first set the Cursor Position result = SetCursorPos(desiredX, desiredY)
'Let's issue a right-button down event result = clickMouse(_MOUSEEVENTF_ABSOLUTE Or _MOUSEEVENTF_RIGHTDOWN, desiredX, desiredY, _NULL, _NULL)
'Now, let's immediately follow that with a right-button up event 'This will most likely result in a context menu being opened at the specified location 'for whatever application (or desktop if no application) is below the coordinates provided result = clickMouse(_MOUSEEVENTF_ABSOLUTE Or _MOUSEEVENTF_RIGHTUP, desiredX, desiredY, _NULL, _NULL) Wait
Function SetCursorPos(X, Y) CallDLL #user32, "SetCursorPos", X As long, _ Y As long, _ SetCursorPos As long End Function
Function clickMouse(dwFlags, dX, dY, dwData, dwExtraInfo) CallDLL #user32, "mouse_event", dwFlags As ulong, _ dX As ulong, _ dY As ulong,_ dwData As ulong,_ dwExtraInfo As ulong, _ result As void End Function Also, note that the mouse_event() API function has been technically deprecated by Microsoft, and it is suggested to use the SendInput() function instead. That being said, they do tend to leave deprecated functions in the API for compatibility purposes. mouse_event function at MSDNSendInput function at MSDN{:0) Brandon Parker
|
|
|
Post by kevinper on Nov 26, 2021 1:48:25 GMT -5
This is fantastic! Thank you so much. I might learn something
|
|
|
Post by Walt Decker on Nov 26, 2021 8:46:01 GMT -5
What I have done:
CALLDLL #user32, "SendMessageA", WinHndl AS ULONG, _WM_LBUTTONDOWN AS ULONG, _MK_LBUTTON AS ULONG, MousePos AS LONG, RetVal AS VOID
=============================================================== WM_LBUTTONDOWN
fwKeys = wParam; // key flags
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor
Parameters
fwKeys
Value of wParam. Indicates whether various virtual keys are down. This parameter can be any combination of the following values:
Value Description MK_CONTROL Set if the CTRL key is down. MK_LBUTTON Set if the left mouse button is down. MK_MBUTTON Set if the middle mouse button is down. MK_RBUTTON Set if the right mouse button is down. MK_SHIFT Set if the SHIFT key is down.
xPos
Value of the low-order word of lParam. Specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
yPos
Value of the high-order word of lParam. Specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
However, you have to perform some calculations to stuff the coordinates into 4 bytes or use a dll to do it for you (a dll for that purpose and others is in this thread titled "NUMBERS").
|
|
|
Post by Brandon Parker on Nov 26, 2021 8:52:11 GMT -5
This is fantastic! Thank you so much. I might learn something Not a problem! Let us know if you need anything else... {:0) Brandon Parker
|
|