void KBDHook_KeyDown(Hooks.LLKHEventArgs e) { if (!_pressedKeys.Contains(e.Keys)) { _pressedKeys.Add(e.Keys); if (_pressedKeys.Count > 1) { text = "+" + e.Keys.ToString(); } else { text = " " + e.Keys.ToString(); } if (WriteToFile) { writer = System.IO.File.AppendText(filename); writer.Write(text); writer.Close(); } else { tbGrab.Text += text; } } }
void KBDHook_KeyUp(Hooks.LLKHEventArgs e) { _pressedKeys.Remove(e.Keys); }
// Хук клавиатуры public static void KBDHook_KeyDown(LLKHEventArgs e) { switch (e.Keys) { case Keys.Left: if (status == 0) inning(1); else if (status == 1) { add_point(reverse, "xx"); e.Hooked = true; } break; case Keys.Right: if (status == 0) inning(2); else if (status == 1) { add_point(reverse, "yy"); e.Hooked = true; } break; case Keys.F1: f1.GoFullscreen(true); e.Hooked = true; break; case Keys.F2: f1.GoFullscreen(false); e.Hooked = true; break; case Keys.F3: f2.GoFullscreen(true); e.Hooked = true; break; case Keys.F4: f2.GoFullscreen(false); e.Hooked = true; break; case Keys.F5: if (status == 1) { switch_inning(); e.Hooked = true; } break; case Keys.Space: if (status == 1) { reverse_switch(); switch_inning(); e.Hooked = true; } break; case Keys.Enter: // Старт ближайшей игры или подтверждение конца партии // ПЕРЕДЕЛАТЬ if (status == -1) { if (fm.dataMatches.Rows.Count > 0) { fm.dataMatches.Rows[0].Selected = true; fm.dataMatches.Rows[0].Cells[0].Selected = true; //fm.dataMatches.Refresh(); fm.start_match(); } } else if (status == 2) { query += "INSERT INTO rounds VALUES (null,'" + match + "','" + (x + y).ToString() + "','" + xx + "','" + yy + "');"; status = 3; //f1.info.Text = ""; history = ""; reset_score(); } break; case Keys.Escape: cancel(); e.Hooked = true; break; } }
/// <summary> /// Hook process messages. /// </summary> /// <param name="nCode"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> static IntPtr HookProcFunction(int nCode, IntPtr wParam, [In] IntPtr lParam) { if (nCode == 0) { LLKHEventArgs args = null; if (localHook) { bool pressed = false; if (lParam.ToInt32() >> 31 == 0) pressed = true; Keys keys = (Keys)wParam.ToInt32(); args = new LLKHEventArgs(keys, pressed, 0U, 0U); if (pressed) { if (KeyDown != null) KeyDown(args); } else { if (KeyUp != null) KeyUp(args); } } else { KBDLLHOOKSTRUCT kbd = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)); bool pressed = false; if (wParam.ToInt32() == 0x100 || wParam.ToInt32() == 0x104) pressed = true; Keys keys = (Keys)kbd.vkCode; args = new LLKHEventArgs(keys, pressed, kbd.time, kbd.scanCode); if (pressed) { if (KeyDown != null) KeyDown(args); } else { if (KeyUp != null) KeyUp(args); } } if (args != null && args.Hooked) return (IntPtr)1; } return API.CallNextHookEx(hHook, nCode, wParam, lParam); }
/// <summary> /// Hook process messages. /// </summary> /// <param name="nCode"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> static IntPtr HookProcFunction(int nCode, IntPtr wParam, [In] IntPtr lParam) { if (nCode == 0) { LLKHEventArgs args = null; if (localHook) { bool pressed = false; if (lParam.ToInt32() >> 31 == 0) { pressed = true; } int keys = wParam.ToInt32(); args = new LLKHEventArgs(keys, pressed, 0U, 0U); if (pressed) { if (KeyDown != null) { KeyDown(args); } } else { if (KeyUp != null) { KeyUp(args); } } } else { KBDLLHOOKSTRUCT kbd = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)); bool pressed = false; if (wParam.ToInt32() == 0x100 || wParam.ToInt32() == 0x104) { pressed = true; } int keys = (int)kbd.vkCode; args = new LLKHEventArgs(keys, pressed, kbd.time, kbd.scanCode); if (pressed) { if (KeyDown != null) { KeyDown(args); } } else { if (KeyUp != null) { KeyUp(args); } } } if (args != null && args.Hooked) { return((IntPtr)1); } } return(API.CallNextHookEx(hHook, nCode, wParam, lParam)); }