private int KeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode == HC_ACTION)
            {
                if (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN)
                {
                    var vkcode = (int)((KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT))).vkCode;
                    var key    = KeyInterop.KeyFromVirtualKey(vkcode);
                    CurrentKey = key;
                    KeyDown?.Invoke(key, vkcode);
                }
                if (wParam == (IntPtr)WM_KEYUP || wParam == (IntPtr)WM_SYSKEYUP)
                {
                    var vkcode = (int)((KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT))).vkCode;
                    var key    = KeyInterop.KeyFromVirtualKey(vkcode);
                    CurrentKey = null;
                    KeyUp?.Invoke(key, vkcode);
                }
            }

            return(CallNextHookEx((int)IntPtr.Zero, nCode, wParam, lParam));
        }
Beispiel #2
0
 /// <summary>
 /// 获取键盘消息
 /// </summary>
 /// <param name="nCode"></param>
 /// <param name="wParam"></param>
 /// <param name="lParam"></param>
 /// <returns></returns>
 private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
 {
     // 如果该消息被丢弃(nCode<0
     if (nCode >= 0)
     {
         KeyboardHookStruct KeyDataFromHook = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
         int keyData = KeyDataFromHook.VkCode;
         //WM_KEYDOWN和WM_SYSKEYDOWN消息,将会引发OnKeyDownEvent事件
         if ((wParam == NativeMethods.WMKEYDOWN || wParam == NativeMethods.WMSYSKEYDOWN))
         {
             Key key = KeyInterop.KeyFromVirtualKey(keyData);
             KeyDown?.Invoke(this, new KeyboardHookEventArgs(key, CapsLockStatus));
         }
         //WM_KEYUP和WM_SYSKEYUP消息,将引发OnKeyUpEvent事件
         if ((wParam == NativeMethods.WMKEYUP || wParam == NativeMethods.WMSYSKEYUP))
         {
             Key key = KeyInterop.KeyFromVirtualKey(keyData);
             KeyUp?.Invoke(this, new KeyboardHookEventArgs(key, CapsLockStatus));
         }
     }
     return(IsHoldKey ? -1 : NativeMethods.CallNextHookEx(hHook, nCode, wParam, lParam));
 }
Beispiel #3
0
        public static Task <bool> JsKeyUp(int e)
        {
            var found      = false;
            var consoleKey = default(ConsoleKey);

            try
            {
                consoleKey = (ConsoleKey)e;
                found      = true;
            }
            catch
            {
                Console.WriteLine($"Cound not find {nameof(ConsoleKey)} for JS key value {e})");
            }

            if (found)
            {
                KeyUp?.Invoke(null, consoleKey);
            }

            return(Task.FromResult(found));
        }
        public FileViewerInternal()
        {
            InitializeComponent();
            InitializeComplete();

            _currentViewPositionCache = new CurrentViewPositionCache(this);

            TextEditor.ActiveTextAreaControl.TextArea.PreviewKeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Escape && !TextEditor.ActiveTextAreaControl.SelectionManager.HasSomethingSelected)
                {
                    EscapePressed?.Invoke();
                }
            };

            TextEditor.TextChanged += (s, e) => TextChanged?.Invoke(s, e);
            TextEditor.ActiveTextAreaControl.HScrollBar.ValueChanged += (s, e) => OnHScrollPositionChanged(EventArgs.Empty);
            TextEditor.ActiveTextAreaControl.VScrollBar.ValueChanged += (s, e) => OnVScrollPositionChanged(EventArgs.Empty);
            TextEditor.ActiveTextAreaControl.TextArea.KeyUp          += (s, e) => KeyUp?.Invoke(s, e);
            TextEditor.ActiveTextAreaControl.TextArea.DoubleClick    += (s, e) => DoubleClick?.Invoke(s, e);
            TextEditor.ActiveTextAreaControl.TextArea.MouseMove      += (s, e) => MouseMove?.Invoke(s, e);
            TextEditor.ActiveTextAreaControl.TextArea.MouseEnter     += (s, e) => MouseEnter?.Invoke(s, e);
            TextEditor.ActiveTextAreaControl.TextArea.MouseLeave     += (s, e) => MouseLeave?.Invoke(s, e);
            TextEditor.ActiveTextAreaControl.TextArea.MouseDown      += (s, e) =>
            {
                SelectedLineChanged?.Invoke(
                    this,
                    new SelectedLineEventArgs(
                        TextEditor.ActiveTextAreaControl.TextArea.TextView.GetLogicalLine(e.Y)));
            };

            HighlightingManager.Manager.DefaultHighlighting.SetColorFor("LineNumbers", new HighlightColor(Color.FromArgb(80, 0, 0, 0), Color.White, false, false));
            TextEditor.ActiveTextAreaControl.TextEditorProperties.EnableFolding = false;

            _lineNumbersControl = new DiffViewerLineNumberControl(TextEditor.ActiveTextAreaControl.TextArea);

            VRulerPosition = AppSettings.DiffVerticalRulerPosition;
        }
Beispiel #5
0
        protected virtual HookResult HookProc(int code, int wParam, ref KeyboardHookData lParam)
        {
            Keys k = (Keys)lParam.vkCode;

            //Check for shift(s), alt, and ctrl.
            //Shift
            if (k == Keys.LShiftKey)
            {
                bLeftShiftHeld = bShiftHeld = (wParam == WM_KEYDOWN);
            }
            else if (k == Keys.RShiftKey)
            {
                bRightShiftHeld = bShiftHeld = (wParam == WM_KEYDOWN);
            }
            //Control
            if ((lParam.vkCode & 0xA2) == 0xA2 || (lParam.vkCode & 0xA3) == 0xA3)
            {
                bCtrlHeld = (wParam == WM_KEYDOWN);
                return(HookResult.NoRelease);
            }
            //Alt
            if ((lParam.vkCode & 0xA4) == 0xA4 || (lParam.vkCode & 0xA5) == 0xA5)
            {
                bAltHeld = (wParam == WM_KEYDOWN);
                return(HookResult.NoRelease);
            }

            if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)
            {
                KeyDown?.Invoke(wParam, lParam);
            }
            else if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP)
            {
                KeyUp?.Invoke(wParam, lParam);
            }

            return(HookResult.Release);
        }
Beispiel #6
0
        /// <summary>
        /// Default hook call, which analyses pressed keys
        /// </summary>
        private IntPtr HookFunc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0)
            {
                return(CallNextHookEx(hookID, nCode, wParam, lParam));
            }
            var iwParam = wParam.ToInt32();

            switch (iwParam)
            {
            case WM_KEYDOWN:
            case WM_SYSKEYDOWN:
                KeyDown?.Invoke((VKeys)Marshal.ReadInt32(lParam));
                break;

            case WM_KEYUP:
            case WM_SYSKEYUP:
                KeyUp?.Invoke((VKeys)Marshal.ReadInt32(lParam));
                break;
            }

            return(CallNextHookEx(hookID, nCode, wParam, lParam));
        }
Beispiel #7
0
        //The listener that will trigger events
        private int KeybHookProc(int Code, int W, int L)
        {
            if (Code < 0)
            {
                return(CallNextHookEx(HookID, Code, W, L));
            }
            try
            {
                KeyEvents kEvent = (KeyEvents)W;
                Int32     vkCode = Marshal.ReadInt32((IntPtr)L);
                if (kEvent == KeyEvents.KeyDown || kEvent == KeyEvents.SKeyDown)
                {
                    KeyDown?.Invoke((Keys)vkCode);
                }
                if (kEvent == KeyEvents.KeyUp || kEvent == KeyEvents.SKeyUp)
                {
                    KeyUp?.Invoke((Keys)vkCode);
                }
            }
            catch { }

            return(CallNextHookEx(HookID, Code, W, L));
        }
Beispiel #8
0
        private static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            var returnCode = CallWindowProc(prevWndProc, hWnd, msg, wParam, lParam);

            switch (msg)
            {
            case WM_GETDLGCODE:
                returnCode = (IntPtr)(returnCode.ToInt32() | DLGC_WANTALLKEYS);
                break;

            case WM_KEYDOWN:
                KeyDown?.Invoke(null, new KeyEventArgs((Keys)wParam));
                break;

            case WM_KEYUP:
                KeyUp?.Invoke(null, new KeyEventArgs((Keys)wParam));
                break;

            case WM_CHAR:
                CharEntered?.Invoke(null, new CharacterEventArgs((char)wParam, lParam.ToInt32()));
                break;

            case WM_IME_SETCONTEXT:
                if (wParam.ToInt32() == 1)
                {
                    ImmAssociateContext(hWnd, hIMC);
                }
                break;

            case WM_INPUTLANGCHANGE:
                ImmAssociateContext(hWnd, hIMC);
                returnCode = (IntPtr)1;
                break;
            }

            return(returnCode);
        }
Beispiel #9
0
        private int HookProc(int code, int wParam, ref KeyboardHookStruct lParam)
        {
            try
            {
                if (code < 0)
                {
                    return(CallNextHookEx(hhook, code, wParam, ref lParam));
                }

                var key = (Keys)lParam.vkCode;
                if (!catchAllKeyDowns && !hookedKeys.Contains(key))
                {
                    return(CallNextHookEx(hhook, code, wParam, ref lParam));
                }

                var kea = new KeyEventArgs(key);
                if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && KeyDown != null)
                {
                    KeyDown(this, kea);
                }
                else if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP)
                {
                    KeyUp?.Invoke(this, kea);
                }

                if (kea.Handled)
                {
                    return(1);
                }

                return(CallNextHookEx(hhook, code, wParam, ref lParam));
            }
            catch
            {
                return(0);
            }
        }
Beispiel #10
0
 private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0)
     {
         if (wParam == KeyDownIntPtr)
         {
             var virtualKey = Marshal.ReadInt32(lParam);
             if (VirtualKey != virtualKey)
             {
                 VirtualKey = virtualKey;
                 KeyDown?.Invoke(null, new KeyboardHookEventArgs(virtualKey, false));
             }
         }
         else if (wParam == SyskeyDownIntPtr)
         {
             var virtualKey = Marshal.ReadInt32(lParam);
             if (VirtualKey != virtualKey)
             {
                 VirtualKey = virtualKey;
                 KeyDown?.Invoke(null, new KeyboardHookEventArgs(virtualKey, true));
             }
         }
         else if (wParam == KeyUpIntPtr)
         {
             var virtualKey = Marshal.ReadInt32(lParam);
             VirtualKey = -1;
             KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, false));
         }
         else if (wParam == SyskeyUpIntPtr)
         {
             var virtualKey = Marshal.ReadInt32(lParam);
             VirtualKey = -1;
             KeyUp?.Invoke(null, new KeyboardHookEventArgs(virtualKey, true));
         }
     }
     return(InteropMethods.CallNextHookEx(HookId, nCode, wParam, lParam));
 }
        // The method responsible for handling the update
        static private void Update(object s, EventArgs e)
        {
            KeyboardState New = Keyboard.GetState();

            Keys[] OldDown = Old.GetPressedKeys();
            Keys[] Down    = New.GetPressedKeys().Where(a => !Old.IsKeyDown(a)).ToArray();
            Keys[] Up      = OldDown.Where(a => !New.IsKeyDown(a)).ToArray();
            Keys[] Held    = OldDown.Where(a => New.IsKeyDown(a)).ToArray();
            foreach (Keys key in Down)
            {
                KeyDown?.Invoke(key);
                // int[]{ticks,tickRate}
                Counter.Add(key, new int[2] {
                    30, 30
                });
            }
            foreach (Keys key in Up)
            {
                Counter.Remove(key);
                KeyUp?.Invoke(key);
            }
            foreach (Keys key in Held)
            {
                Counter[key][0]--;
                if (Counter[key][0] > 0)
                {
                    continue;
                }
                Counter[key][0] = Counter[key][1];
                if (Counter[key][1] > 15)
                {
                    Counter[key][1]--;
                }
                KeyHeld?.Invoke(key);
            }
            Old = New;
        }
Beispiel #12
0
        static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr returnCode = CallWindowProc(_prevWndProc, hWnd, msg, wParam, lParam);

            switch (msg)
            {
            case WmGetdlgcode:
                returnCode = (IntPtr)(returnCode.ToInt32() | DlgcWantallkeys);
                break;

            case WmKeydown:
                KeyDown?.Invoke(null, new KeyEventArgs((Keys)wParam));
                break;

            case WmKeyup:
                KeyUp?.Invoke(null, new KeyEventArgs((Keys)wParam));
                break;

            case WmChar:
                CharEntered?.Invoke(null, new CharacterEventArgs((char)wParam, lParam.ToInt32()));
                break;

            case WmImeSetcontext:
                if (wParam.ToInt32() == 1)
                {
                    ImmAssociateContext(hWnd, _hImc);
                }
                break;

            case WmInputlangchange:
                ImmAssociateContext(hWnd, _hImc);
                returnCode = (IntPtr)1;
                break;
            }

            return(returnCode);
        }
Beispiel #13
0
 /// <summary>
 /// The callback for the keyboard hook
 /// </summary>
 /// <param name="code">The hook code, if it isn't >= 0, the function shouldn't do anyting</param>
 /// <param name="wParam">The event type</param>
 /// <param name="lParam">The keyhook event information</param>
 /// <returns></returns>
 public int hookProc(int code, int wParam, ref keyboardHookStruct lParam)
 {
     if (code >= 0)
     {
         Keys key = (Keys)lParam.vkCode;
         if (HookedKeys.Contains(key))
         {
             KeyEventArgs kea = new KeyEventArgs(key);
             if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && (KeyDown != null))
             {
                 KeyDown.Invoke(this, kea);
             }
             else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && (KeyUp != null))
             {
                 KeyUp.Invoke(this, kea);
             }
             if (kea.Handled)
             {
                 return(1);
             }
         }
     }
     return(CallNextHookEx(hhook, code, wParam, ref lParam));
 }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (!Enabled)
            {
                return;
            }

            var state = Keyboard.GetState();

            var oldPressed = _previousState.GetPressedKeys();
            var newPressed = state.GetPressedKeys();

            for (var i = 0; i < oldPressed.Length; ++i)
            {
                if (Array.IndexOf(newPressed, oldPressed[i]) < 0)
                {
                    var e = new KeyEventArgs(oldPressed[i], KeyState.Down, KeyState.Up);

                    KeyUp?.Invoke(this, e);
                }
            }

            for (var i = 0; i < newPressed.Length; ++i)
            {
                if (Array.IndexOf(oldPressed, newPressed[i]) < 0)
                {
                    var e = new KeyEventArgs(newPressed[i], KeyState.Up, KeyState.Down);

                    KeyDown?.Invoke(this, e);
                }
            }

            _previousState = state;
        }
Beispiel #15
0
        IntPtr KeyBoardHookFunc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            // parse system messages
            if (nCode >= 0)
            {
                if (KeyBoardMessages.WM_KEYDOWN == (KeyBoardMessages)wParam)
                {
                    KeyDown?.Invoke((Keys)Marshal.ReadInt32(lParam));
                }

                //Need to catch SYSKEYDOWN for alt key
                if (KeyBoardMessages.WM_SYSKEYDOWN == (KeyBoardMessages)wParam)
                {
                    KeyDown?.Invoke((Keys)Marshal.ReadInt32(lParam));
                }

                if (KeyBoardMessages.WM_KEYUP == (KeyBoardMessages)wParam)
                {
                    KeyUp?.Invoke((Keys)Marshal.ReadInt32(lParam));
                }
            }

            return(NativeMethods.CallNextHookEx(keyBoardHookID, nCode, wParam, lParam));
        }
Beispiel #16
0
        private IntPtr HookCallback(int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam)
        {
            if (nCode >= 0)
            {
                if (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN)
                {
                    int  vkCode = lParam.vkCode;
                    int  flags  = lParam.flags;
                    Keys key    = (Keys)vkCode;
                    if (KeyEvented?.Invoke(key, KeyboardEventType.KEYDOWN) == false)
                    {
                        return((IntPtr)1);
                    }
                    if (KeyDown?.Invoke(key) == false)
                    {
                        return((IntPtr)1);
                    }
                }
                else if (wParam == (IntPtr)WM_KEYUP || wParam == (IntPtr)WM_SYSTEMKEYUP)
                {
                    int  vkCode = lParam.vkCode;
                    int  flags  = lParam.flags;
                    Keys key    = (Keys)vkCode;
                    if (KeyEvented?.Invoke(key, KeyboardEventType.KEYUP) == false)
                    {
                        return((IntPtr)1);
                    }
                    if (KeyUp?.Invoke(key) == false)
                    {
                        return((IntPtr)1);
                    }
                }
            }

            return(API.CallNextHookEx(_hookID, nCode, wParam, ref lParam));
        }
 private int HookProc(int code, int wParam, ref User32.KeyboardHookStruct lParam)
 {
     if (code >= 0)
     {
         var key = (Keys)lParam.vkCode;
         if (HookedKeys.Contains(key))
         {
             var kea = new KeyEventArgs(key);
             if (wParam == User32.WM_KEYDOWN || wParam == User32.WM_SYSKEYDOWN)
             {
                 KeyDown?.Invoke(this, kea);
             }
             if (wParam == User32.WM_KEYUP || wParam == User32.WM_SYSKEYUP)
             {
                 KeyUp?.Invoke(this, kea);
             }
             if (kea.Handled)
             {
                 return(1);
             }
         }
     }
     return(User32.CallNextHookEx(_hhook, code, wParam, ref lParam));
 }
Beispiel #18
0
        public void OnKeyUp(SkiVirtualKey key)
        {
            lock (_downKeys)
            {
                if (!_downKeys.Remove(key))
                {
                    return;
                }
            }

            lock (_keyBindingsMap)
            {
                if (_keyBindingsMap.TryGetValue(key, out var keyBindings))
                {
                    var matchedKeyBindings = keyBindings.Where(b => b.IsPressed);
                    foreach (var matchedKeyBinding in matchedKeyBindings)
                    {
                        matchedKeyBinding.OnReleased();
                    }
                }
            }

            KeyUp.Invoke(key);
        }
Beispiel #19
0
        /// <summary>
        /// The callback for the keyboard hook
        /// </summary>
        /// <param name="code">The hook code, if it isn't >= 0, the function shouldn't do anyting</param>
        /// <param name="wParam">The event type</param>
        /// <param name="lParam">The keyhook event information</param>
        /// <returns></returns>
        public IntPtr HookCallback(int code, IntPtr wParam, ref WinAPI.KeyboardHookStruct lParam)
        {
            if (code >= 0)
            {
                var key = (System.Windows.Forms.Keys)lParam.vkCode;

                if (_hookedKeys.Contains(key))
                {
                    var wpfKey    = InputUtil.WinformsToWPFKey(key);
                    var eventArgs = new GlobalKeyEventArgs(wpfKey, IsShiftPressed(), IsCtrlPressed(), IsAltPressed());

                    if (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN)
                    {
                        KeyDown?.Invoke(this, eventArgs);
                    }
                    else if (wParam == (IntPtr)WM_KEYUP || wParam == (IntPtr)WM_SYSKEYUP)
                    {
                        KeyUp?.Invoke(this, eventArgs);
                    }
                }
            }

            return(WinAPI.CallNextHookEx(hookID, code, wParam, ref lParam));
        }
Beispiel #20
0
 internal virtual void InvokeKeyUp(DisplayObject target, DisplayObject currentTarget)
 {
     KeyUp?.Invoke(target, currentTarget);
 }
Beispiel #21
0
        private unsafe int HookFunc(IntPtr userdata, IntPtr ev)
        {
            SDL_Event *e = (SDL_Event *)ev;

            switch (e->type)
            {
            case SDL_EventType.SDL_WINDOWEVENT:
                switch (e->window.windowEvent)
                {
                case SDL_WindowEventID.SDL_WINDOWEVENT_ENTER:
                    Mouse.MouseInWindow = true;
                    break;

                case SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE:
                    Mouse.MouseInWindow = false;
                    break;

                case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED:
                    // SDL_CaptureMouse(SDL_bool.SDL_TRUE);
                    //Log.Message(LogTypes.Debug, "FOCUS");
                    break;

                case SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST:
                    //Log.Message(LogTypes.Debug, "NO FOCUS");
                    //SDL_CaptureMouse(SDL_bool.SDL_FALSE);

                    break;

                case SDL_WindowEventID.SDL_WINDOWEVENT_TAKE_FOCUS:
                    //Log.Message(LogTypes.Debug, "TAKE FOCUS");
                    break;

                case SDL_WindowEventID.SDL_WINDOWEVENT_HIT_TEST:

                    break;
                }

                break;

            case SDL_EventType.SDL_SYSWMEVENT:
                break;

            case SDL_EventType.SDL_KEYDOWN:
                KeyDown?.Raise(e->key);

                break;

            case SDL_EventType.SDL_KEYUP:
                KeyUp.Raise(e->key);

                break;

            case SDL_EventType.SDL_TEXTINPUT:
                string s = StringHelper.ReadUTF8(e->text.text);

                if (!string.IsNullOrEmpty(s))
                {
                    TextInput.Raise(s);
                }

                break;

            case SDL_EventType.SDL_MOUSEMOTION:
                Mouse.Update();
                if (Mouse.IsDragging)
                {
                    MouseDragging.Raise();
                }

                if (Mouse.IsDragging && !_dragStarted)
                {
                    DragBegin.Raise();
                    _dragStarted = true;
                }

                break;

            case SDL_EventType.SDL_MOUSEWHEEL:
                Mouse.Update();
                bool isup = e->wheel.y > 0;
                MouseWheel.Raise(isup);

                break;

            case SDL_EventType.SDL_MOUSEBUTTONUP:
            case SDL_EventType.SDL_MOUSEBUTTONDOWN:
                Mouse.Update();
                bool isDown = e->type == SDL_EventType.SDL_MOUSEBUTTONDOWN;

                if (_dragStarted && !isDown)
                {
                    DragEnd.Raise();
                    _dragStarted = false;
                }

                SDL_MouseButtonEvent mouse = e->button;

                switch ((uint)mouse.button)
                {
                case SDL_BUTTON_LEFT:
                    Mouse.LButtonPressed = isDown;

                    if (isDown)
                    {
                        Mouse.Begin();
                        Mouse.LDropPosition     = Mouse.Position;
                        Mouse.CancelDoubleClick = false;
                        uint ticks = SDL_GetTicks();

                        if (Mouse.LastLeftButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks)
                        {
                            Mouse.LastLeftButtonClickTime = 0;

                            if (LeftMouseDoubleClick != null && !LeftMouseDoubleClick.Invoke())
                            {
                                LeftMouseButtonDown.Raise();
                            }
                            else
                            {
                                Mouse.LastLeftButtonClickTime = 0xFFFF_FFFF;
                            }

                            break;
                        }

                        LeftMouseButtonDown.Raise();
                        Mouse.LastLeftButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks;
                    }
                    else
                    {
                        if (Mouse.LastLeftButtonClickTime != 0xFFFF_FFFF)
                        {
                            LeftMouseButtonUp.Raise();
                        }
                        Mouse.End();
                    }

                    break;

                case SDL_BUTTON_MIDDLE:
                    Mouse.MButtonPressed = isDown;

                    if (isDown)
                    {
                        Mouse.Begin();
                        Mouse.MDropPosition     = Mouse.Position;
                        Mouse.CancelDoubleClick = false;
                        uint ticks = SDL_GetTicks();

                        if (Mouse.LastMidButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks)
                        {
                            if (MidMouseDoubleClick != null && !MidMouseDoubleClick.Invoke())
                            {
                                MidMouseButtonDown.Raise();
                            }
                            Mouse.LastMidButtonClickTime = 0;

                            break;
                        }

                        MidMouseButtonDown.Raise();
                        Mouse.LastMidButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks;
                    }
                    else
                    {
                        MidMouseButtonUp.Raise();
                        Mouse.End();
                    }

                    break;

                case SDL_BUTTON_RIGHT:
                    Mouse.RButtonPressed = isDown;

                    if (isDown)
                    {
                        Mouse.Begin();
                        Mouse.RDropPosition     = Mouse.Position;
                        Mouse.CancelDoubleClick = false;
                        uint ticks = SDL_GetTicks();

                        if (Mouse.LastRightButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks)
                        {
                            Mouse.LastRightButtonClickTime = 0;

                            if (RightMouseDoubleClick != null && !RightMouseDoubleClick.Invoke())
                            {
                                RightMouseButtonDown.Raise();
                            }
                            else
                            {
                                Mouse.LastRightButtonClickTime = 0xFFFF_FFFF;
                            }

                            break;
                        }

                        RightMouseButtonDown.Raise();
                        Mouse.LastRightButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks;
                    }
                    else
                    {
                        if (Mouse.LastRightButtonClickTime != 0xFFFF_FFFF)
                        {
                            RightMouseButtonUp.Raise();
                        }
                        Mouse.End();
                    }

                    break;

                case SDL_BUTTON_X1:

                    break;

                case SDL_BUTTON_X2:

                    break;
                }

                break;
            }

            //switch (e->type)
            //{
            //    // KEYBOARD
            //    case SDL_EventType.SDL_KEYDOWN:
            //        OnKeyDown(new InputKeyboardEvent(KeyboardEvent.Down, e->key.keysym.sym, 0, e->key.keysym.mod));

            //        break;
            //    case SDL_EventType.SDL_KEYUP:
            //        OnKeyUp(new InputKeyboardEvent(KeyboardEvent.Up, e->key.keysym.sym, 0, e->key.keysym.mod));

            //        break;
            //    case SDL_EventType.SDL_TEXTINPUT:
            //        string s = StringHelper.ReadUTF8(e->text.text);

            //        if (!string.IsNullOrEmpty(s))
            //            OnTextInput(new InputKeyboardEvent(KeyboardEvent.TextInput, SDL_Keycode.SDLK_UNKNOWN, 0, SDL_Keymod.KMOD_NONE) {KeyChar = s});

            //        break;

            //    // MOUSE
            //    case SDL_EventType.SDL_MOUSEBUTTONDOWN:
            //        MouseDown.Raise();
            //        OnMouseDown(new InputMouseEvent(MouseEvent.Down, CovertMouseButton(e->button.button), e->button.clicks, e->button.x, e->button.y, 0, SDL_Keymod.KMOD_NONE));

            //        break;
            //    case SDL_EventType.SDL_MOUSEBUTTONUP:
            //        MouseUp.Raise();
            //        OnMouseUp(new InputMouseEvent(MouseEvent.Up, CovertMouseButton(e->button.button), e->button.clicks, e->button.x, e->button.y, 0, SDL_Keymod.KMOD_NONE));

            //        switch (e->button.clicks)
            //        {
            //            case 1:
            //                MouseClick.Raise();
            //                break;
            //            case 2:
            //                MouseDoubleClick.Raise();
            //                break;
            //        }

            //        break;
            //    case SDL_EventType.SDL_MOUSEMOTION:
            //        MouseMove.Raise();
            //        OnMouseMove(new InputMouseEvent(MouseEvent.Move, CovertMouseButton(e->button.button), 0, e->motion.x, e->motion.y, 0, SDL_Keymod.KMOD_NONE));

            //        break;
            //    case SDL_EventType.SDL_MOUSEWHEEL:
            //        OnMouseWheel(new InputMouseEvent(MouseEvent.WheelScroll, MouseButton.Middle, 0, e->wheel.x, e->wheel.y, 0, SDL_Keymod.KMOD_NONE));

            //        break;
            //}

            return(1);
        }
        private void OnKeyUp(Keys key)
        {
            modifiers.KeyUp(key);

            KeyUp?.Invoke(this, new KeyEventArgs(key));
        }
Beispiel #23
0
 public void onKeyUp(KeyUp ku)
 {
     EKeyUp = ku;
 }
Beispiel #24
0
 /// <summary>
 /// Function to fire the key up event.
 /// </summary>
 /// <param name="key">Key that's pressed.</param>
 /// <param name="scan">Scan code data.</param>
 private void OnKeyUp(Keys key, int scan) => KeyUp?.Invoke(this, new GorgonKeyboardEventArgs(key, GetModifiers(), scan));
Beispiel #25
0
        /// <summary>
        /// A callback function which will be called every time a keyboard activity detected.
        /// https://docs.microsoft.com/en-us/windows/win32/winmsg/lowlevelkeyboardproc
        /// </summary>
        /// <param name="code">
        /// Specifies whether the hook procedure must process the message.
        /// If code is HC_ACTION, the hook procedure must process the message.
        /// If code is less than zero, the hook procedure must pass the message to the
        /// CallNextHookEx function without further processing and must return the
        /// value returned by CallNextHookEx.
        /// </param>
        /// <param name="wParam">
        /// Specifies whether the message was sent by the current thread.
        /// If the message was sent by the current thread, it is nonzero; otherwise, it is zero.
        /// </param>
        /// <param name="lParam">
        /// Pointer to a CWPSTRUCT structure that contains details about the message.
        /// </param>
        /// <returns>
        /// If code is less than zero, the hook procedure must return the value returned by CallNextHookEx.
        /// If code is greater than or equal to zero, it is highly recommended that you call CallNextHookEx
        /// and return the value it returns; otherwise, other applications that have installed WH_CALLWNDPROC
        /// hooks will not receive hook notifications and may behave incorrectly as a result. If the hook
        /// procedure does not call CallNextHookEx, the return value should be zero.
        /// </returns>
        private IntPtr KeyboardHookProc(int code, uint wParam, IntPtr lParam)
        {
            //Indicates if any of the underlaying events set the e.Handled flag.
            var handled = false;

            //If it was Ok and there are no listeners.
            if (code < 0 || KeyDown == null && KeyUp == null && KeyPress == null)
            {
                return(CallNextHookEx(_keyboardHookHandle, code, wParam, lParam));
            }

            //Read structure KeyboardHookStruct at lParam
            var keyboard   = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
            var isInjected = (keyboard.Flags & 0x10) != 0;

            if (KeyDown != null && (wParam == MessageKeydown || wParam == MessageSystemKeyDown))
            {
                #region Raise KeyDown

                var isDownShift    = (GetKeyState(KeyShift) & 0x80) == 0x80;
                var isDownCapslock = GetKeyState(KeyCapital) != 0;


                var e = new CustomKeyEventArgs(KeyInterop.KeyFromVirtualKey(keyboard.KeyCode), isDownCapslock ^ isDownShift, isInjected);

                KeyDown?.Invoke(this, e);

                handled = e.Handled;

                #endregion
            }

            if (KeyPress != null && wParam == MessageKeydown)
            {
                #region Raise KeyPress

                var isDownShift    = (GetKeyState(KeyShift) & 0x80) == 0x80;
                var isDownCapslock = GetKeyState(KeyCapital) != 0;

                var keyState = new byte[256];
                GetKeyboardState(keyState);
                var inBuffer = new byte[2];

                if (ToAscii(keyboard.KeyCode, keyboard.ScanCode, keyState, inBuffer, keyboard.Flags) == 1)
                {
                    var key = (char)inBuffer[0];
                    if (isDownCapslock ^ isDownShift && char.IsLetter(key))
                    {
                        key = char.ToUpper(key);
                    }

                    var e = new CustomKeyPressEventArgs(key);
                    KeyPress?.Invoke(this, e);

                    handled = handled || e.Handled;
                }

                #endregion
            }

            if (KeyUp != null && (wParam == MessageKeyUp || wParam == MessageSystemKeyUp))
            {
                #region Raise KeyUp

                var e = new CustomKeyEventArgs(KeyInterop.KeyFromVirtualKey(keyboard.KeyCode), false, isInjected);

                KeyUp?.Invoke(this, e);

                handled = handled || e.Handled;

                #endregion
            }

            //If event handled in application do not handoff to other listeners.
            return(handled ? new IntPtr(1) : CallNextHookEx(_keyboardHookHandle, code, wParam, lParam));
        }
Beispiel #26
0
 public void PerformKeyUp(KeyboardKeyEventArgs e)
 {
     KeyUp?.Invoke(e);
     FocusedControl?.PerformKeyUp(e);
 }
Beispiel #27
0
 /// <summary>
 /// Queues a <see cref="KeyUp"/> event for the passed <see cref="KeyCode"/>.
 /// </summary>
 /// <param name="key"><see cref="KeyCode"/> of the key that was released.</param>
 private void TriggerKeyUp(KeyCode key)
 {
     KeyUp e = new KeyUp();
     e.Key = key.ToString();
     QueueEvent(e);
 }
Beispiel #28
0
        private void init(GameWindow game)
        {
            if (_game != null)
            {
                return;
            }
            _game             = game;
            _originalOSCursor = game.Cursor;

            _cursor.PropertyChanged += (sender, e) =>
            {
                if (_cursor.Cursor != null)
                {
                    _game.Cursor = MouseCursor.Empty;
                }
            };
            game.MouseDown += (sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                _actions.Enqueue(() => MouseDown.InvokeAsync(new API.MouseButtonEventArgs(_hitTest.ObjectAtMousePosition, button, MousePosition)));
            };
            game.MouseUp += (sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                _actions.Enqueue(() => MouseUp.InvokeAsync(new API.MouseButtonEventArgs(_hitTest.ObjectAtMousePosition, button, MousePosition)));
            };
            game.MouseMove += (sender, e) =>
            {
                _mouseX = e.Mouse.X;
                _mouseY = e.Mouse.Y;
                _actions.Enqueue(() => MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition)));
            };
            game.KeyDown += (sender, e) =>
            {
                API.Key key = convert(e.Key);
                _keysDown.Add(key);
                if (isInputBlocked())
                {
                    return;
                }
                _actions.Enqueue(() => KeyDown.InvokeAsync(new KeyboardEventArgs(key)));
            };
            game.KeyUp += (sender, e) =>
            {
                API.Key key = convert(e.Key);
                _keysDown.Remove(key);
                if (isInputBlocked())
                {
                    return;
                }
                _actions.Enqueue(() => KeyUp.InvokeAsync(new KeyboardEventArgs(key)));
            };

            _events.OnRepeatedlyExecuteAlways.Subscribe(onRepeatedlyExecute);
        }
 private void KeyboardDevice_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
 {
     KeyUp?.Invoke(this, new KeyEventArgs(KeyboardState.Empty, Keys.A, ' '));
 }
Beispiel #30
0
        private static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr returnCode = CallWindowProc(prevWndProc, hWnd, msg, wParam, lParam);

            switch (msg)
            {
            case WM_GETDLGCODE:
                returnCode = (IntPtr)DLGC_WANTALLKEYS;
                break;

            case WM_CHAR:
                CharEntered?.Invoke(null, new CharacterEventArgs((char)wParam, (int)lParam));
                break;

            case WM_KEYDOWN:
                KeyDown?.Invoke(null, new KeyEventArgs((Keys)wParam));
                break;

            case WM_KEYUP:
                KeyUp?.Invoke(null, new KeyEventArgs((Keys)wParam));
                break;

            case WM_LBUTTONDOWN:
                MouseSelection.left   = (int)lParam & 0xffff;
                MouseSelection.top    = (int)lParam >> 16;
                MouseSelection.right  = MouseSelection.left;
                MouseSelection.bottom = MouseSelection.top;
                if (Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    Acp      acp     = textBox.GetAcpByRange(MouseSelection);
                    if (acp.Start >= 0)
                    {
                        textBox.SetSelection(acp.Start, acp.End);
                        Selecting = true;
                    }
                }
                break;

            case WM_MOUSEMOVE:
                MouseSelection.right  = (int)lParam & 0xffff;
                MouseSelection.bottom = (int)lParam >> 16;
                if (Selecting && Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    RECT range = new RECT
                    {
                        left   = Math.Min(MouseSelection.left, MouseSelection.right),
                        top    = Math.Max(MouseSelection.top, MouseSelection.bottom),
                        right  = Math.Max(MouseSelection.left, MouseSelection.right),
                        bottom = Math.Min(MouseSelection.top, MouseSelection.bottom)
                    };
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    Acp      acp     = textBox.GetAcpByRange(range);
                    if (acp.Start >= 0)
                    {
                        textBox.SetSelection(acp.Start, acp.End);
                        textBox.SetSelState(MouseSelection.left > MouseSelection.right ? SelState.SEL_AE_END : SelState.SEL_AE_START);
                    }
                }
                break;

            case WM_LBUTTONUP:
                Selecting = false;
                break;

            default:
                break;
            }
            return(returnCode);
        }
Beispiel #31
0
 /// <inheritdoc cref="KeyUp" />
 private void ControlOnKeyUp(object sender, System.Windows.Forms.KeyEventArgs args) => KeyUp?.Invoke(sender, new KeyEventArgs(args));
Beispiel #32
0
 private void EditOnKeyUp(object sender, KeyEventArgs e)
 {
     KeyUp?.Invoke(sender, e);
 }