Exemplo n.º 1
0
        protected override IntPtr Callback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                var kdb = Marshal.PtrToStructure <KBDLLHOOKSTRUCT>(lParam);

                if (HookMode.Global.Equals(Mode))
                {
                    var keyboardEventArgs = new KeyboardHookEventArgs(kdb.vkCode, kdb.scanCode, kdb.time, kdb.flags);

                    switch (wParam.ToInt32())
                    {
                    case WM_KEYDOWN:
                    case WM_SYSKEYDOWN:
                        HandleKeyDownHookEvent(keyboardEventArgs);
                        break;

                    case WM_KEYUP:
                    case WM_SYSKEYUP:
                        HandleKeyReleasedHookEvent(keyboardEventArgs);
                        break;
                    }

                    // Trap key chain if it has been handled
                    if (keyboardEventArgs.Handled)
                    {
                        return(new IntPtr(1));
                    }
                }
            }

            return(WinAPI.CallNextHookEx(instance, nCode, wParam, lParam));
        }
Exemplo n.º 2
0
        private void HandleKeyReleasedHookEvent(KeyboardHookEventArgs args)
        {
            OnHook?.Invoke(args);

            lock (downKeys)
            {
                bool removed = downKeys.Remove(args.KeyCode);

                OnRelease?.Invoke(args);

                if (removed)
                {
                    OnPress?.Invoke(args);
                }
            }
        }
Exemplo n.º 3
0
        private void OnKeyPressed(KeyboardHookEventArgs args)
        {
            // 0 - Mana: first right panel, first bp
            if (args.KeyCode == 48)
            {
                Sender.Use(3358, 132, 2624, 454);
            }

            // R - SD: first right panel, second bp
            if (args.KeyCode == 82)
            {
                Sender.Click(true, 3358, 206);
            }

            // T - MW: first right panel, third bp
            if (args.KeyCode == 84)
            {
                Sender.Click(true, 3358, 280);
            }
        }
Exemplo n.º 4
0
        private void HandleKeyDownHookEvent(KeyboardHookEventArgs args)
        {
            OnHook?.Invoke(args);

            lock (downKeys)
            {
                // Save button to prevent multiple events and also to recognize successfull key presses (down and up)
                bool added = downKeys.Add(args.KeyCode);

                if (added)
                {
                    OnHold?.Invoke(args); // First time
                }
                else
                {
                    if (!settings.HookHoldEventOnce)
                    {
                        OnHold?.Invoke(args);
                    }
                }
            }
        }