LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call Library Function Node - GetCursorPos

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!

0 Kudos
Message 1 of 16
(298 Views)

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?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 16
(257 Views)

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!

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 16
(242 Views)

@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:

Screenshot 2024-04-29 08.38.51.png

 

On the 64-bit is not important, but recommended to set as shown above anyway.

Refer to GetCursorPos function.

0 Kudos
Message 4 of 16
(238 Views)

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.

0 Kudos
Message 5 of 16
(210 Views)

Hi Max,

 

can't you use the ValueSignalling property of the boolean control instead of moving the mouse cursor and emulating user actions?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 16
(191 Views)

I would like to generate mousedown event, not value change.

0 Kudos
Message 7 of 16
(189 Views)

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 16
(187 Views)

This is just an example, in the real software I need to generate mousedown event for a string.

0 Kudos
Message 9 of 16
(181 Views)

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…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 16
(173 Views)