Example Code

Multiple Key Down/Key Up event handling

Code and Documents

Attachment

Overview

This example shows how multiple key down/key up events can be interpreted and processed using a state machine architecture. This example expands on the functionality of the "Multiple Button KeyDown Event" example found at the following link: https://decibel.ni.com/content/docs/DOC-13223

Description

I was interested in writing a program which interprets arrow key presses in the same way any racing game does.

This behaviour is best explained by examples:

  1. If arrow key “Up” and arrow key “Left” are pressed at the same time the virtual car starts turning to the left while following a curved trajectory which contains a forward component.
  2. If the “Left” arrow key is released, the car starts moving forwards in a straight line.
  3. If “Up” + “Left” + “Right” keys are pressed at the same time, the left and right commands cancel out and the car acts as if only the “Up” arrow key is pressed.
  4. Pressing keys other than arrow keys does not interfere with the trajectory the car follows.

Steps to Execute Code

     Download the "Multiple arrow key press example" zip file which is saved for both LV 2013 and LV 2010. Run the "Arrow key presses" VI.

Arrow key presses.png


Requirements

LV 2010 or above

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

Contributors