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));
        }
Пример #2
0
        private void OnKeyPressed(object sender, GlobalKeyboardHookEventArgs e)
        {
            Console.WriteLine(e.KeyboardData.VirtualCode);
            if (e.KeyboardState == GlobalKeyboardHook.KeyboardState.KeyDown)
            {
                switch (e.KeyboardData.VirtualCode)
                {
                case 37:
                    if (view == 1)
                    {
                        Console.WriteLine("Setting to concealed images");
                        img1m.Source = pixelBin("Resources/male icon.png");
                        img2m.Source = pixelBin("Resources/male icon.png");
                        img5m.Source = pixelBin("Resources/male icon.png");

                        img1f.Source = pixelBin("Resources/female icon.png");
                        img2f.Source = pixelBin("Resources/female icon.png");
                        img5f.Source = pixelBin("Resources/female icon.png");
                        view         = 0;
                    }
                    break;

                case 39:
                    if (view == 0)
                    {
                        Console.WriteLine("Setting to shown images");
                        img1m.Source = pixelBin("Resources/1m.png");
                        img2m.Source = pixelBin("Resources/2m.png");
                        img5m.Source = pixelBin("Resources/5m.png");

                        img1f.Source = pixelBin("Resources/1f.png");
                        img2f.Source = pixelBin("Resources/2f.png");
                        img5f.Source = pixelBin("Resources/5f.png");
                        view         = 1;
                    }
                    break;
                }
            }
        }