Example Code

Mouse simulation

Code and Documents

Attachment

Download All

Overview
This VI allows you to programatically control your mouse from LabVIEW, and can be useful in automation. It makes use of the User32.dll functions SetCursorPos and mouse_event

 
Description
This VI gives the option for mouse up and mouse down events on the left, middle and right mouse buttons. It also allows you to set the mouse position (in pixels) before performing an action.

For a "click" you will need to run the VI twice to create a mouse down, then a mouse up event. If you just create a mouse down event, this will be equivical to clicking and holding, until the mouse receives another input on that button, or you generate a mouse up event.

 
Requirements

  • LabVIEW 2013 (or compatible)


Steps to Implement or Execute Code

  1. Place SubVI
  2. Wire the "action" terminal on the top left of the subVI to select the button and action from the enum.
  3. (optional) Wire the x and y position terminals to set the position of the mouse prior to the desired action
  4. If you wired positions, make send a true to the "Set mouse position prior to action?" terminal.
  5. Run the code

 

Additional Information or References

block diagram

sss.png

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

 

 

Matt H
Applications Engineer
National Instruments UK

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