none
Recognize Pen or Mouse at Control.MouseEnter? RRS feed

  • Question

  • Hi @all!

    At the Control.MouseEnter-Event I need to know wether the Control was entered by a pen (Tablet SDK) oder mouse. Is there a way to achieve that? The only way I can imagine is by putting an active InkCollector on the control, waiting for the NewInAirPAcket-Event to raise and check the PenID. But I don't want to have the InkCollector being enabled all the time. Furtermore you see the small pen tip after entering the Control, which doesn't look very professional but irritates the user.

    Any suggestion would be great! Thank you very much!

    Kind regards

    TopperDEL

    Tuesday, October 10, 2006 10:35 AM

Answers

  • Hi TopperDEL,

    mouse messages generated by a pen get tagged with a special value (0xFF515700). This allows an app to discern mouse input from pen input without hooking up an InkCollector. In the Winforms APIs this tag is not directly exposed, but you can get to it with a PInvoke. See sample code below.

    Just FYI: if you want a different cursor on an InkCollector, you can set the InkCollector.Cursor property to the desired cursor.

    Thanks, Stefan Wick

     

    using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class Form1 : Form
    {
        [DllImport("user32")]
        public static extern uint GetMessageExtraInfo();
        public const int WM_MOUSEMOVE = 0x0200;
        public const uint MI_WP_SIGNATURE = 0xFF515700;

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_MOUSEMOVE)
            {
                uint extraInfo = GetMessageExtraInfo();
                if ((extraInfo & 0xFFFFFF00) == MI_WP_SIGNATURE)
                {
                    Text = "Pen";
                }
                else
                {
                    Text = "Mouse";
                }
            }
        }
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }
    }

    Tuesday, October 10, 2006 1:31 PM

All replies

  • Hi TopperDEL,

    mouse messages generated by a pen get tagged with a special value (0xFF515700). This allows an app to discern mouse input from pen input without hooking up an InkCollector. In the Winforms APIs this tag is not directly exposed, but you can get to it with a PInvoke. See sample code below.

    Just FYI: if you want a different cursor on an InkCollector, you can set the InkCollector.Cursor property to the desired cursor.

    Thanks, Stefan Wick

     

    using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class Form1 : Form
    {
        [DllImport("user32")]
        public static extern uint GetMessageExtraInfo();
        public const int WM_MOUSEMOVE = 0x0200;
        public const uint MI_WP_SIGNATURE = 0xFF515700;

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_MOUSEMOVE)
            {
                uint extraInfo = GetMessageExtraInfo();
                if ((extraInfo & 0xFFFFFF00) == MI_WP_SIGNATURE)
                {
                    Text = "Pen";
                }
                else
                {
                    Text = "Mouse";
                }
            }
        }
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }
    }

    Tuesday, October 10, 2006 1:31 PM
  • Hi Stefan!

    Thank you very much indeed for your help! It seems to me that this is exactly the solution to my problem. I'll try it.

    Sincerely

    TopperDEL

    [Edit]

    I checked it out and it works perfect! Thank you very much!

    Tuesday, October 10, 2006 1:41 PM