Exemplo n.º 1
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WinAPI.WM_INPUT)
            {
                WinAPI.RAWINPUT input   = new WinAPI.RAWINPUT();
                int             outSize = 0;
                int             size    = Marshal.SizeOf(typeof(WinAPI.RAWINPUT));
                outSize = WinAPI.GetRawInputData(m.LParam, WinAPI.RawInputCommand.Input, out input, ref size, Marshal.SizeOf(typeof(WinAPI.RAWINPUTHEADER)));
                if (outSize != -1)
                {
                    if (input.Header.Type == WinAPI.RawInputType.Mouse)
                    {
                        if (input.Data.Mouse.Data.ButtonFlags != WinAPI.RawMouseButtons.None)
                        {
                            KMHook.ListenMouse(input.Data.Mouse.Data.ButtonFlags);
                        }
                    }
                    if (input.Header.Type == WinAPI.RawInputType.Keyboard)
                    {
                        var kbd = input.Data.Keyboard;
                        var k   = kbd.VKey;
                        switch (k)
                        {
                        case (int)Keys.ShiftKey:
                            if (kbd.MakeCode == 42)
                            {
                                k = (int)Keys.LShiftKey;
                            }
                            else
                            {
                                k = (int)Keys.RShiftKey;
                            }
                            break;

                        case (int)Keys.ControlKey:
                            if (kbd.Flags < 2)
                            {
                                k = (int)Keys.LControlKey;
                            }
                            else
                            {
                                k = (int)Keys.RControlKey;
                            }
                            break;

                        case (int)Keys.Menu:
                            if (kbd.Flags < 2)
                            {
                                k = (int)Keys.LMenu;
                            }
                            else
                            {
                                k = (int)Keys.RMenu;
                            }
                            break;
                        }
                        KMHook.ListenKeyboard(k, input.Data.Keyboard.Message);
                    }
                }
            }
            base.WndProc(ref m);
        }