Example Code

Event Structures (Basics)

Code and Documents



Events are caused by actions the user performs. For example, clicking the mouse generates a mouse event, pressing a key on the keyboard generates a keyboard event, and so on. When a system event occurs, the operating system is responsible for identifying and responding to the event. Any application running on a system can react to the system event by executing code written for that specific system event.

In LabVIEW, you can use the Event structure to handle events in an application. As with a Case structure, you can add multiple cases to the Event structure. You can then configure those cases to handle one or more events. When those events occur, LabVIEW executes the corresponding case.

Steps to Complete

Functions»Programming»Structures»Event Structure

Event Structures have one or more subdiagrams, or event cases, exactly one of which executes when the structure executes. The Event structure waits until an event happens, then executes the appropriate case to handle that event. Right-click the structure border to add new event cases and configure which events to handle. Wire a value to the Timeout terminal at the top left of the Event structure to specify the number of milliseconds the Event structure should wait for an event to occur. The default is –1, indicating never to time out.

The Event Data Node is attached to the inside left and right borders of each event case. The node identifies the data LabVIEW returns when an event occurs. The node displays data that is different in each case of the Event structure depending on which event(s) you configure that case to handle. If you configure a single case to handle multiple events, only the data that is common to all handled event types is available.

Additional Notes

Dev Zone Tutorial: Event-Driven Programming in LabVIEW

Dev Zone Example: Generating Keystrokes in LabVIEW using Event Structures

Dev Zone Example: Tab Control with While Loop and Event Structure Example

Dev Zone Example: Monitoring Mouse Clicks Using Event Structures

National Instruments
Applications Engineer

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

NI Employee (retired)

The first line of your introduction mentions a video, but I have seen no link or embedded video.  Could you help me out on where to find this video?  Thanks

Field Engineer