04-28-2024 01:59 PM
I need to get the position of the mouse cursor within LabVIEW. I've been attempting to use the GetCursorPos function with the Call Library Function Node, but I'm encountering some difficulties in getting the correct mouse position.
Could someone kindly provide guidance or a sample implementation on how to properly get the mouse position using the Call Library Function Node? Any assistance would be greatly appreciated.
Regardless, I would appreciate a few words on how to work with the Call Library Function Node.
Thank you in advance for your help!
04-29-2024 12:24 AM
Hi Max,
@maxnoder1995 wrote:
I'm encountering some difficulties in getting the correct mouse position.
Which "difficulties" to you encounter?
Do you have some specific problems and questions?
@maxnoder1995 wrote:
I would appreciate a few words on how to work with the Call Library Function Node.
You configure the DLL function to be called and need to set the correct I/O parameters…
Again: any specific problem?
04-29-2024 01:40 AM
I guess your problem is the POINT parameter. You are lucky as this is easy todo in LabVIEW. Create a cluster with two 32-bit integers, configure a Call Library Node to have one parameter set to Adapt to Type and a return value of unsigned 32-bit integer. Don’t forget to set the Calling convention to stdcall, since this is a Windows API call.
But this only works for flat structures that do not contain any pointers like variable sized strings or arrays. LabVIEW strings and arrays are NOT binary compatible with C strings or arrays!
The returned position is however in screen coordinates, which are not easily mappable to a LabVIEW window and even one more step complicated to LabVIEW controls!
04-29-2024 01:40 AM - edited 04-29-2024 01:42 AM
@maxnoder1995 wrote:
I need to get the position of the mouse cursor within LabVIEW. I've been attempting to use the GetCursorPos function with the Call Library Function Node, but I'm encountering some difficulties in getting the correct mouse position.
Could someone kindly provide guidance or a sample implementation on how to properly get the mouse position using the Call Library Function Node? Any assistance would be greatly appreciated.
Regardless, I would appreciate a few words on how to work with the Call Library Function Node.
Here is working example: "GetCursorPos" function in the user32.dll.
Important to set stdcall calling conventions on 32-bit LabVIEW, otherwise stack gets damaged:
On the 64-bit is not important, but recommended to set as shown above anyway.
Refer to GetCursorPos function.
04-29-2024 03:29 AM
Thanks for the responses, I'm trying to click a boolean button programmatically only. So I thought of saving the current cursor position, placing the cursor at the position of the button, making a click and then returning the cursor to the position I saved at the beginning.
It works but does not meet extreme conditions if the mouse moves quickly while the program is running.
I am trying to execute this logic using mouse_event but I don't know where my mistake is.
04-29-2024 03:58 AM
04-29-2024 04:00 AM
I would like to generate mousedown event, not value change.
04-29-2024 04:02 AM
Hi Max,
@maxnoder1995 wrote:
I would like to generate mousedown event, not value change.
Why?
You can control your button programmatically within LabVIEW, no need to call the Windows API…
04-29-2024 04:05 AM
This is just an example, in the real software I need to generate mousedown event for a string.
04-29-2024 04:13 AM
Hi Max,
@maxnoder1995 wrote:
This is just an example, in the real software I need to generate mousedown event for a string.
Then why do you provide an example with a boolean button?
Why don't you use the KeyFocus property of your string control?
(Again: you can control the string using LabVIEW functions , no need to go over Windows API…)