#736 – Finding the Maximum Number of Touch Points at Run-time

You can write code that discovers at run-time the number of touch points supported by the hardware that you’re running on.  You do this by calling the GetSystemMetrics Win32 API call.

    class Program
    {
        [DllImport("user32.dll")]
        static extern int GetSystemMetrics(int nIndex);

        // Index passed in to GetSystemMetrics() indicates
        // what data we're asking for.
        private const int SM_DIGITIZER = 94;
        private const int SM_MAXIMUMTOUCHES = 95;

        // Masks used to check results from SM_DIGITIZER check
        private const int NID_READY = 0x80;
        private const int NID_MULTI_INPUT = 0x40;

        static void Main(string[] args)
        {
            string info;

            int digitizer = GetSystemMetrics(SM_DIGITIZER);

            if ((digitizer & (NID_READY + NID_MULTI_INPUT)) == NID_READY + NID_MULTI_INPUT)
            {
                int numTouchPoints = GetSystemMetrics(SM_MAXIMUMTOUCHES);
                info = string.Format("Multitouch ready, {0} inputs supported", numTouchPoints);
            }
            else
                info = "Multitouch not supported";

            Console.WriteLine(info);
            Console.ReadLine();
        }
    }

736-001

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #736 – Finding the Maximum Number of Touch Points at Run-time

  1. Hi, I wondering is that touch input number can be change?, I mean to reduce it, for example from 10 inputs to 1 input only.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: