Getting Touch Input from a Screen

Last modified by Microchip on 2023/11/10 11:03

This page contains information for the Graphics Library found in Microchip Libraries for Applications (MLA). It is not relevant for the MPLAB® Harmony Graphics Library.

The TouchGetMsg Function

Graphic Application projects created by Microchip typically have the TouchGetMsg(&msg) function as the first function called after the Display routine has finished processing the display list.

TouchGetMsg determines if and where a touch event has occurred. A touch event is a touch, a release, or a movement on the screen. If an event is observed, the data structure MSG is populated with the touch info. The data structure is then passed on to GFX_GOL_ObjectMessage for processing.

TouchGetMsg(&msg) function

Supplied by Microchip, TouchGetMsg is considered part of the application and not part of the Graphics Library. TouchGetMsg was written to read the specific resistive-touch display panels used on Microchip evaluation boards. If you wish to use display panels other than those offered by Microchip, you will have to rewrite the function to work with the selected display panel.

Msg Data Structure

TouchGetMsg will populate a data structure each time it is called. In Microchip Graphics applications, this data structure is named Msg. In addition to display panels, the Msg data structure was designed to record touch events on other media such as keypads or "side buttons".

This article explains how TouchGetMsg works with touch displays. For a complete description of the Msg data structure and how it works with other input devices, please review the graphics message structure page.

Defined in the file gfx-gol.h, the structure of the message is:

Structure of the message

Msg can be defined in any file with ​GFX_GOL_MESSAGE  Msg;.

When Populated by TouchGetMsg, Msg will contain:

Message Filled Example

From TouchGetMsg(&Msg):

  • Msg.type always contains value: TYPE_TOUCHSCREEN
  • Msg.param1 contains the X position of the event
  • Msg.param2 contains the Y position of the event
  • Msg.uiEvent contains the code for the specific event detected
uiEvent Codes
Event CodeTouch Event Detected
EVENT_INVALIDScreen was untouched last time and remains untouched
EVENT_MOVEScreen was touched last time but this time the touch is in a different location
EVENT_PRESSScreen was untouched last time and is touched this time
EVENT_STILLPRESSScreen was touched last time and is still touched in the same location
EVENT_RELEASEScreen was touched last time, but is now untouched

Once filled, Msg is passed on to GFX_GOL_ObjectMessage for processing.

For a complete description of the Msg data structure and how it works with other input devices, please review the "Messaging Structure" page.


Learn More