Back to contents pageHow to get button press events

How to get button press events

Summary

This article shows how to detect tag button press events using the Ubisense .NET API.





Prerequisites

None. You can use this article on its own.



Example material

Save this link to get a zip file of the example material


Guide

Before you start, remember to:



1) Add event handlers to detect button presses

Add an event handler OnButton for the Ubisense.UData.Data.ObjectButtonPressed relation as follows:


    // Add an insert event handler to detect the addition of new rows
    Ubisense.UData.Data.ObjectButtonPressed.AddInsertHandler(
        data_schema, OnButton);

    // Add an update event handler to detect updates of existing rows
    Ubisense.UData.Data.ObjectButtonPressed.AddUpdateHandler(
        data_schema, OnButton);



2) Define the handler methods

You need to define handlers for new rows being inserted and existing rows being updated in order to react to all button presses. In this example, the update handler simply calls the insert handler with the new row as the argument:


    // Update event handler that just calls the insert event handler with the new row
    private static void OnButton(
        Ubisense.UData.Data.ObjectButtonPressed.RowType _old,
        Ubisense.UData.Data.ObjectButtonPressed.RowType _row)
    {
        OnButton(_row);
    }

    // Insert event handler that outputs the button presses to the screen
    private static void OnButton(
        Ubisense.UData.Data.ObjectButtonPressed.RowType _row)
    {
        // _row.button_ contains the index of the button pressed. Compact tags
        // have button 1; slim tags have buttons 1 and 2.

        // _row.object_ contains the Ubisense.ULocationIntegration.Tag whose button
        // was pressed.

        // _row.timestamp_ contains the Universal time of the button press.
    }

Whenever a tag button press is detected, your handler code will execute.



Back to top