示例#1
0
        public IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            bool fEatKeyStroke = false;

            var wparamTyped = wParam.ToInt32();

            if (wparamTyped == 0x101 && Pressing == true)
            {
                Pressing = false;
            }

            if (wparamTyped == 0x100 || wparamTyped == 0x104)
            {
                object o = Marshal.PtrToStructure(lParam, typeof(LowLevelKeyInputArgs));
                LowLevelKeyInputArgs p = (LowLevelKeyInputArgs)o;

                var eventArguments = new GlobalKeyHookEventArgs(p, (VKeyState)wparamTyped);

                EventHandler <GlobalKeyHookEventArgs> handler = KeyboardDown;
                handler?.Invoke(this, eventArguments);

                fEatKeyStroke = eventArguments.Handled;
            }

            return(fEatKeyStroke ? (IntPtr)1 : CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
        }
示例#2
0
        void Hook_KeyboardDown(object sender, GlobalKeyHookEventArgs e)
        {
            //System.Windows.MessageBox.Show(e.VKeyCode.ToString());

            if (e.VKeyCode == VKeyCode.Three)
            {
                if (GlobalKeyHook.IsKeyDown(VKeyCode.LeftAlt) && GlobalKeyHook.IsKeyDown(VKeyCode.LeftShift) && GlobalKeyHook.Hook.Pressing == false)
                {
                    cap.CaptureMyScreen();
                    GlobalKeyHook.Hook.Pressing = true;
                }
            }

            if (e.VKeyCode == VKeyCode.Four)
            {
                if (GlobalKeyHook.IsKeyDown(VKeyCode.LeftAlt) && GlobalKeyHook.IsKeyDown(VKeyCode.LeftShift) && GlobalKeyHook.Hook.Pressing == false)
                {
                    if (SelectMouseCursor == null)
                    {
                        SelectMouseCursor         = new SelectMouseCursor();
                        SelectMouseCursor.Owner   = App.Current.MainWindow;
                        SelectMouseCursor.Closed += delegate
                        {
                            SelectMouseCursor = null;
                        };
                        SelectMouseCursor.Show();
                    }
                    else
                    {
                        SelectMouseCursor.Activate();
                    }
                    GlobalKeyHook.Hook.Pressing = true;
                }
            }

            if (e.VKeyCode == VKeyCode.Six)
            {
                if (GlobalKeyHook.IsKeyDown(VKeyCode.LeftAlt) && GlobalKeyHook.IsKeyDown(VKeyCode.LeftShift) && GlobalKeyHook.Hook.Pressing == false)
                {
                    if (Setting == null)
                    {
                        Setting         = new ScreenshotLikeAMac.UI.Setting();
                        Setting.Owner   = App.Current.MainWindow;
                        Setting.Closed += delegate
                        {
                            Setting = null;
                        };
                        Setting.Show();
                    }
                    else
                    {
                        Setting.Activate();
                    }
                    GlobalKeyHook.Hook.Pressing = true;
                }
            }

            if (e.VKeyCode == VKeyCode.ESC)
            {
                if (SelectMouseCursor != null)
                {
                    MouseHook.stop();
                    SelectMouseCursor.Close();
                    SelectMouseCursor = null;
                }
            }
        }