Share via


Identifying a Mouse

With the MultiPoint Mouse SDK, you can identify which mouse clicked a button and then display that mouse pointer ID on the button.

To identify the mouse that clicked the button

  1. Get an instance of the button that was clicked.

  2. Cast the “sender” object to a MultipointButton, as follows:

    MultipointButton btn = (MultipointButton)sender;

  3. To see information about the mouse device that was clicked, cast the RoutedEventArgs to a MultipointMouseEventArgs as follows:

    MultipointMouseEventArgs multipointargs = 
        e as MultipointMouseEventArgs;
    

    The as operator is used here to prevent InvalidCastExceptions if the cast fails.

  4. Test that multipointargs is not null before you perform the required action, as follows:

    if (multipointargs != null) 
    {
        // perform required action
    }
    
  5. To determine which mouse was clicked, view the Id property in the DeviceInfo object. You can output this information to the button as follows:

    mpButton.Content = 
        String.Format("Mouse #{0} Clicked me",
        multipointargs.DeviceInfo.Id);