public IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam) { bool fEatKeyStroke = false; var wparamTyped = wParam.ToInt32(); if (Enum.IsDefined(typeof(KeyboardState), wparamTyped)) { object o = Marshal.PtrToStructure(lParam, typeof(LowLevelKeyboardInputEvent)); LowLevelKeyboardInputEvent p = (LowLevelKeyboardInputEvent)o; var eventArguments = new GlobalKeyboardHookEventArgs(p, (KeyboardState)wparamTyped); EventHandler <GlobalKeyboardHookEventArgs> handler = KeyboardPressed; handler?.Invoke(this, eventArguments); fEatKeyStroke = eventArguments.Handled; } return(fEatKeyStroke ? (IntPtr)1 : CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)); }
private static void KeyBoardHook_KeyboardPressed(object sender, GlobalKeyboardHookEventArgs e) { if (!TextShown) { ControlForm = new ControlForm(); var p = Cursor.Position; ControlForm.SetDesktopLocation(p.X, p.Y); ControlForm.SetText("OKOKOK" + test++); ControlForm.Show(); try { var fptExam = Process.GetProcessesByName("FPT-Exam")[0]; SetWindowPos(fptExam.MainWindowHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE); } catch (Exception) { } SetWindowPos(ControlForm.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } else { ControlForm.Close(); } TextShown = !TextShown; }