private static void RegisterKeyboardHookMethod() { ProcessModule mainModule = Process.GetCurrentProcess().MainModule; SebKeyCapture.objKeyboardProcess = new SebKeyCapture.LowLevelProc(SebKeyCapture.CaptureKey); SebKeyCapture.objMouseProcess = new SebKeyCapture.LowLevelProc(SebKeyCapture.CaptureMouseButton); SebKeyCapture.ptrKeyboardHook = SebKeyCapture.SetWindowsHookEx(13, SebKeyCapture.objKeyboardProcess, SebKeyCapture.GetModuleHandle(mainModule.ModuleName), 0U); SebKeyCapture.ptrMouseHook = SebKeyCapture.SetWindowsHookEx(14, SebKeyCapture.objMouseProcess, SebKeyCapture.GetModuleHandle(mainModule.ModuleName), 0U); }
private static void UnregisterKeyboardHookMethod() { if (SebKeyCapture.ptrKeyboardHook != IntPtr.Zero) { SebKeyCapture.UnhookWindowsHookEx(SebKeyCapture.ptrKeyboardHook); SebKeyCapture.ptrKeyboardHook = IntPtr.Zero; } if (!(SebKeyCapture.ptrMouseHook != IntPtr.Zero)) { return; } SebKeyCapture.UnhookWindowsHookEx(SebKeyCapture.ptrMouseHook); SebKeyCapture.ptrMouseHook = IntPtr.Zero; }
private static IntPtr CaptureMouseButton(int nCode, IntPtr wp, IntPtr lp) { if (nCode >= 0) { if ((bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, "touchOptimized") && (bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, "enableTouchExit")) { SebKeyCapture.TestTouchExitSequence(Cursor.Position); } if (SebKeyCapture.DisableMouseButton(nCode, wp, lp)) { return((IntPtr)1); } } return(SebKeyCapture.CallNextHookEx(SebKeyCapture.ptrMouseHook, nCode, wp, lp)); }
private static IntPtr CaptureKey(int nCode, IntPtr wp, IntPtr lp) { if (nCode >= 0) { SebKeyCapture.TestAppExitSequences(wp, lp); SebKeyCapture.KBDLLHOOKSTRUCT structure = (SebKeyCapture.KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lp, typeof(SebKeyCapture.KBDLLHOOKSTRUCT)); if ((bool)SEBClientInfo.getSebSetting("enableAltTab")["enableAltTab"]) { if (structure.key == Keys.Tab && structure.flags == 32 && (int)wp == 260) { if (SebKeyCapture.Tab_Pressed_First_Time && (int)wp == 260) { SEBClientInfo.SebWindowsClientForm.ShowApplicationChooserForm(); if (SebKeyCapture.Tab_Pressed_First_Time) { SebKeyCapture.Tab_Pressed_First_Time = false; } return((IntPtr)1); } if (!SebKeyCapture.Tab_Pressed_First_Time && (int)wp == 260) { SEBClientInfo.SebWindowsClientForm.SelectNextListItem(); return((IntPtr)1); } } if ((structure.key == Keys.LMenu && structure.flags == 128 || structure.key == Keys.RMenu && structure.flags == 129) && (int)wp == 257) { SEBClientInfo.SebWindowsClientForm.HideApplicationChooserForm(); SebKeyCapture.Tab_Pressed_First_Time = true; } } if (SebKeyCapture.DisableKey(wp, lp)) { return((IntPtr)1); } } return(SebKeyCapture.CallNextHookEx(SebKeyCapture.ptrKeyboardHook, nCode, wp, lp)); }
private static void TestAppExitSequences(IntPtr wp, IntPtr lp) { if (wp == (IntPtr)256) { if (SebKeyCapture.SetAndTestCtrlQExitSequence(wp, lp)) { SEBClientInfo.SebWindowsClientForm.ShowCloseDialogForm(); } if (!SebKeyCapture.SetAndTestExitKeySequence(wp, lp) || (bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, "ignoreExitKeys")) { return; } SEBClientInfo.SebWindowsClientForm.ExitApplication(true); } else { if (!(wp == (IntPtr)257)) { return; } SebKeyCapture.ResetCtrlQExitSequence(wp, lp); SebKeyCapture.ResetExitKeySequence(wp, lp); } }
private static bool SetAndTestExitKeySequence(IntPtr wp, IntPtr lp) { SebKeyCapture.KBDLLHOOKSTRUCT structure = (SebKeyCapture.KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lp, typeof(SebKeyCapture.KBDLLHOOKSTRUCT)); SebKeyCapture.SetExitKeys(); if (structure.key == SebKeyCapture.exitKey1) { SebKeyCapture.exitKey1_Pressed = true; } else if (structure.key == SebKeyCapture.exitKey2) { SebKeyCapture.exitKey2_Pressed = true; } else if (structure.key == SebKeyCapture.exitKey3) { SebKeyCapture.exitKey3_Pressed = true; } else { SebKeyCapture.exitKey1_Pressed = false; SebKeyCapture.exitKey2_Pressed = false; SebKeyCapture.exitKey3_Pressed = false; } return(SebKeyCapture.exitKey1_Pressed && SebKeyCapture.exitKey2_Pressed && SebKeyCapture.exitKey3_Pressed); }