Beispiel #1
0
        public int MyKeyboardProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                KeyBoardHookStruct kbh = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct));
                if (kbh.vkCode == (int)Keys.LWin)
                {
                    //MessageBox.Show("拦截了Win键");
                    return(1);
                }
                if (kbh.vkCode == (int)Keys.F4 && Control.ModifierKeys == Keys.Alt)
                {
                    //MessageBox.Show("拦截了Alt+F4");
                    return(1);
                }

                if (kbh.vkCode == (int)Keys.Tab && Control.ModifierKeys == Keys.Alt)
                {
                    //MessageBox.Show("拦截了Alt+Tab");
                    return(1);
                }

                if (kbh.vkCode == (int)Keys.Escape && Control.ModifierKeys == Keys.Control)
                {
                    //  MessageBox.Show("拦截了Ctrl+Esc");
                    return(1);
                }

                if (kbh.vkCode == (int)Keys.Tab && Control.ModifierKeys == (Keys.Alt | Keys.Control))
                {
                    //拦截 Ctrl + Alt + Tab
                    return(1);
                }

                if (kbh.vkCode == (int)Keys.Delete && (int)Control.ModifierKeys == ((int)Keys.Alt | (int)Keys.Control))
                {
                    //   MessageBox.Show("捕捉到Ctrl+Alt+Delete");
                    return(1);
                }


                //屏蔽掉其他程序的快捷键

                if (((int)Control.ModifierKeys & (int)Keys.Control) != 0)
                {
                    //Console.WriteLine("control pressed");
                    return(0);
                }
                if (((int)Control.ModifierKeys & (int)Keys.Alt) != 0)
                {
                    //Console.WriteLine("alt pressed");
                    return(0);
                }
            }
            //return 0;
            return(Win32API.CallNextHookEx(hook.hHook, nCode, wParam, lParam));
        }
Beispiel #2
0
        private int myKeyboardHookProc(int nCode, int wParam, IntPtr lParam)
        {
            KeyBoardHookStruct kbh = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct));

            if (kbh.vkCode == (int)(Keys.L) && Control.ModifierKeys == (Keys.Control | Keys.Alt))
            {
                lockScreen();
                return(1);
            }
            //return 0;
            return(Win32API.CallNextHookEx(hook.hHook, nCode, wParam, lParam));
        }
Beispiel #3
0
        /// <summary>
        /// 屏蔽键盘
        /// </summary>
        /// <param name="nCode"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        public static int KeyBoardHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                KeyBoardHookStruct kbh = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct));


                // 屏蔽左"f1-f12"
                if ((kbh.vkCode == (int)Keys.F1) || (kbh.vkCode == (int)Keys.F2) ||
                    (kbh.vkCode == (int)Keys.F3) || (kbh.vkCode == (int)Keys.F4) ||
                    (kbh.vkCode == (int)Keys.F4) || (kbh.vkCode == (int)Keys.F5) ||
                    (kbh.vkCode == (int)Keys.F6) || (kbh.vkCode == (int)Keys.F7) ||
                    (kbh.vkCode == (int)Keys.F8) || (kbh.vkCode == (int)Keys.F9) ||
                    (kbh.vkCode == (int)Keys.F10) || (kbh.vkCode == (int)Keys.F11) || (kbh.vkCode == (int)Keys.F1))
                {
                    return(1);
                }


                // 屏蔽左"Ctrl"、右"Ctrl"
                if ((kbh.vkCode == (int)Keys.LControlKey) || (kbh.vkCode == (int)Keys.RControlKey))
                {
                    return(1);
                }
                // 屏蔽左"alt"
                if ((kbh.vkCode == (int)Keys.Alt))
                {
                    return(1);
                }

                /* 屏蔽左"WIN"、右"Win"
                 * if ((kbh.vkCode == (int)Keys.LWin) || (kbh.vkCode == (int)Keys.RWin))
                 * {
                 *  return 1;
                 * }*/
                //屏蔽Ctrl+Esc
                if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Control)
                {
                    return(1);
                }
                //屏蔽Alt+f4
                if (kbh.vkCode == (int)Keys.F4 && (int)Control.ModifierKeys == (int)Keys.Alt)
                {
                    return(1);
                }
                //屏蔽Alt+Esc
                if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Alt)
                {
                    return(1);
                }
                //屏蔽Alt+Tab
                if (kbh.vkCode == (int)Keys.Tab && (int)Control.ModifierKeys == (int)Keys.Alt)
                {
                    return(1);
                }
                //截获Ctrl+Shift+Esc
                if (kbh.vkCode == (int)Keys.Escape &&
                    (int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Shift)
                {
                    return(1);
                }

                //截获Ctrl+Alt+Dle
                if (kbh.vkCode == (int)Keys.Delete &&
                    (int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Alt)
                {
                    return(1);
                }
            }
            return(CallNextHookEx(hHook, nCode, wParam, lParam));
        }