private int HookCallbackProc(int nCode, System.IntPtr wParam, System.IntPtr lParam)
        {
            if (nCode < 0)
            {
                return(ColorPicker_NativeMethods.CallNextHookEx(m_hHook, nCode, wParam, lParam));
            }
            else
            {
                //Marshall the data from the callback.
                WinUtil.KeyboardHookStruct hookstruct =
                    (WinUtil.KeyboardHookStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(lParam, typeof(WinUtil.KeyboardHookStruct));

                if (OnKeyDown != null && wParam.ToInt32() == WinUtil.WM_KEYDOWN)
                {
                    System.Windows.Forms.Keys key = (System.Windows.Forms.Keys)hookstruct.vkCode;
                    if ((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Shift) == System.Windows.Forms.Keys.Shift)
                    {
                        key |= System.Windows.Forms.Keys.Shift;
                    }
                    if ((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) == System.Windows.Forms.Keys.Control)
                    {
                        key |= System.Windows.Forms.Keys.Control;
                    }

                    var e = new System.Windows.Forms.KeyEventArgs(key);
                    e.Handled = false;
                    OnKeyDown(e);
                    if (e.Handled)
                    {
                        return(1);
                    }
                }
                int result = 0;
                if (m_hHook != 0)
                {
                    result = ColorPicker_NativeMethods.CallNextHookEx(m_hHook, nCode, wParam, lParam);
                }
                return(result);
            }
        }
        public void SetHook(bool enable)
        {
            if (enable && m_hHook == 0)
            {
                m_HookCallback = new ColorPicker_NativeMethods.HookProc(HookCallbackProc);
                System.Reflection.Module module = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0];
                m_hHook = ColorPicker_NativeMethods.SetWindowsHookEx(WinUtil.WH_KEYBOARD_LL, m_HookCallback, System.Runtime.InteropServices.Marshal.GetHINSTANCE(module),
                                                                     0);
                if (m_hHook == 0)
                {
                    System.Windows.Forms.MessageBox.Show(
                        "SetHook Failed. Please make sure the 'Visual Studio Host Process' on the debug setting page is disabled");
                    return;
                }
                return;
            }

            if (enable == false && m_hHook != 0)
            {
                ColorPicker_NativeMethods.UnhookWindowsHookEx(m_hHook);
                m_hHook = 0;
            }
        }