To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This VI demonstrates how to control an external Windows Media Player using keystrokes.
Description
Sometimes it is desirable to control external programs using a LabVIEW VI. This can easily be done if the program accepts keyboard shortcuts or custom hot keys can be set to control the program. In this case playback on an external (not embedded) Windows Media Player is performed with LabVIEW.
A top-level vi, "Controlling WMP Window.vi," handles the user interface. The vi opens a media file in an external Windows Media Player window. The program then uses a sub-vi, "Find Window.vi," to obtain a handle for the window. A handle is actually a Windows data type (see Windows Data Types for more information). When playback controls are pressed, the program sends the keystroke command to the Windows Media Player window using "SendKey.vi." When the main vi is exited, the ALT-F4 key combination is sent to close Windows Media Player.
This example can be adapted for any program accepting keyboard shortcuts. The program should be opened using an Active X reference or the System Exec VI (see "System Exec VI" in LabVIEW Help). The window name input for the "Find Window.vi" must also be updated.
Requirements
Steps to Implement or Execute Code
Additional Information or References
VI Snippet
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
It works, however when Windows Media Player is minimized after it shows on the screen, the Pause and Stop keys stop working. I am using ML2009 SP1. WIndos XP, WMP 10.0.