Example Code

Control an External Program using Keystrokes - Windows Media Player Using LabVIEW

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

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Select a media file first.
  2. Run the VI.
  3. Play, pause or stop the video using the button on the front pane.

Additional Information or References
VI Snippet

001.png

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

Applications Engineer
National Instruments

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

Comments
wprice
Member
Member
on

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.