예제 #1
0
        static IntPtr LowLevelKeyboardHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            var khs = (HookAPI.KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(HookAPI.KeyboardHookStruct));

            if (nCode < 0)
            {
                return(HookAPI.CallNextHookEx(m_hHook, nCode, wParam, lParam));
            }
            else
            {
                if (mode == 1)
                {
                    if ((khs.Flags & 128) != 0)
                    {
                        current_pressed = true;
                    }

                    GCHandle gch = GCHandle.Alloc(m_hHook);

                    return(HookAPI.CallNextHookEx(m_hHook, nCode, wParam, lParam));
                }
                else
                {
                    if (mode == 2)
                    {
                        current_pressed = true;
                    }
                    IntPtr val = new IntPtr(1);
                    return(val);
                }
            }
        }
예제 #2
0
 static void Unhook()
 {
     HookAPI.UnhookWindowsHookEx(m_hHook);
     gc_h.Free();
 }
예제 #3
0
 static void SetHook()
 {
     m_callback = new HookAPI.LowLevelKeyboardProcDelegate(LowLevelKeyboardHookProc);
     gc_h       = GCHandle.Alloc(m_callback);
     m_hHook    = HookAPI.SetWindowsHookEx(WH_KEYBOARD_LL, m_callback, HookAPI.GetModuleHandle(IntPtr.Zero), 0);
 }