Example Code

Get Mouse Poisition and Front Panel position

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This VI will take in a reference for the VI it is being called by and then output information about the position of; the VI front panel, the mouse in repect to the screen and the mouse in respect to the front panel.

 

Description

Want to know where your Front Panel is positioned or what co-ordinates your mouse cursor is at? This VI finds the position of your Front Panel, the position of your mouse in respect to the desktop and the position of your mouse in respect to your front panel. It is designed to be used as a subVI in one of your programs, taking in a reference to the VI that is calling it and outputting all the values mentioned above as 32bit integers.

 

Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Put the Front Panel and mouse cursor at a place on the screen.
  2. Run the VI.
  3. This VI finds the position of your Front Panel, the position of your mouse in respect to the desktop and the position of your mouse in respect to your front panel. 

Additional Information or References 

VI Snippet

152.png

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

James W
Controls Systems Engineer
STFC

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
TejaskumarPatel
Member
Member
on

Is there any possibilities to detect if mouse (cursor) is on 1st screen (Primary monitor) or Secondary monitor.

MFG

Kumar

Tejaskumar Patel | (CLD)
JTG_Wilson
Member
Member
on

I don't have a second monitor so I can't test this idea myself BUT you might be able to check the mouse position and compare it to the results from the Primary Workspace Property (http://zone.ni.com/reference/en-XX/help/371361J-01/lvprop/app_dsplyprim_wrkspc/) to see if it falls within this boundary, if it does then the mouse is on the primary monitor if not then it must be on the secondary monitor. This is just my initial thinking, and there is probably a better way to do it, but I would think that this could work.

James W
Controls Systems Engineer
STFC