Exemple #1
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            settings    = Settings.Load("settings.json");
            catDetector = new CatDetector(settings.TimeBetweenKeyPresses);

            rdoCatOff.Checked = true;
            rdoCatOn.Checked  = false;
            hookHandler       = new WindowsKeyboard.HookHandlerDelegate(KeyboardHookHandler);

            keyboardHandlerId = WindowsKeyboard.SetLowLevelHook(hookHandler);
            this.FormClosing += FrmMain_FormClosing;
        }
Exemple #2
0
        private IntPtr KeyboardHookHandler(int nCode, IntPtr wParam, ref WindowsKeyboard.KBDLLHOOKSTRUCT lParam)
        {
#if DEBUG
            Debug.WriteLine((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond).ToString() + "ms: " + nCode
                            + " " + wParam + " " + lParam.flags + " " + lParam.vkCode);
#endif
            CatMode = CatMode || catDetector.IsCat(WindowsKeyboard.IsSpecialKey(lParam), nCode, wParam, lParam);

            if (CatMode)
            {
                // only ignore keydown events to prevent Ctrl, Shift, etc. from sticking
                if (WindowsKeyboard.IsKeyDown(wParam))
                {
                    keypressLog.Add(DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
                    return((IntPtr)1);
                }
                else
                {
                    timerNoKeyPress.Start();
                }
            }

            return(WindowsKeyboard.CallNextHookEx(keyboardHandlerId, nCode, wParam, ref lParam));
        }
Exemple #3
0
 private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     WindowsKeyboard.UnhookWindowsHookEx(keyboardHandlerId);
 }