Beispiel #1
0
        private void PostProcessInput(object sender, ProcessInputEventArgs e)
        {
            // PreviewKeyDown --> KeyDown
            if (e.StagingItem.Input.RoutedEvent == Keyboard.PreviewKeyDownEvent)
            {
                CheckForDisconnectedFocus();

                if (!e.StagingItem.Input.Handled)
                {
                    KeyEventArgs previewKeyDown = (KeyEventArgs)e.StagingItem.Input;

                    // Dig out the real key.
                    bool isSystemKey         = false;
                    bool isImeProcessed      = false;
                    bool isDeadCharProcessed = false;
                    Key  key = previewKeyDown.Key;
                    if (key == Key.System)
                    {
                        isSystemKey = true;
                        key         = previewKeyDown.RealKey;
                    }
                    else if (key == Key.ImeProcessed)
                    {
                        isImeProcessed = true;
                        key            = previewKeyDown.RealKey;
                    }
                    else if (key == Key.DeadCharProcessed)
                    {
                        isDeadCharProcessed = true;
                        key = previewKeyDown.RealKey;
                    }

                    KeyEventArgs keyDown = new KeyEventArgs(this, previewKeyDown.UnsafeInputSource, previewKeyDown.Timestamp, key);
                    keyDown.SetRepeat(previewKeyDown.IsRepeat);

                    // Mark the new event as SystemKey as appropriate.
                    if (isSystemKey)
                    {
                        keyDown.MarkSystem();
                    }
                    else if (isImeProcessed)
                    {
                        // Mark the new event as ImeProcessed as appropriate.
                        keyDown.MarkImeProcessed();
                    }
                    else if (isDeadCharProcessed)
                    {
                        keyDown.MarkDeadCharProcessed();
                    }

                    keyDown.RoutedEvent   = Keyboard.KeyDownEvent;
                    keyDown.ScanCode      = previewKeyDown.ScanCode;
                    keyDown.IsExtendedKey = previewKeyDown.IsExtendedKey;
                    e.PushInput(keyDown, e.StagingItem);
                }
            }

            // PreviewKeyUp --> KeyUp
            if (e.StagingItem.Input.RoutedEvent == Keyboard.PreviewKeyUpEvent)
            {
                CheckForDisconnectedFocus();

                if (!e.StagingItem.Input.Handled)
                {
                    KeyEventArgs previewKeyUp = (KeyEventArgs)e.StagingItem.Input;

                    // Dig out the real key.
                    bool isSystemKey         = false;
                    bool isImeProcessed      = false;
                    bool isDeadCharProcessed = false;
                    Key  key = previewKeyUp.Key;
                    if (key == Key.System)
                    {
                        isSystemKey = true;
                        key         = previewKeyUp.RealKey;
                    }
                    else if (key == Key.ImeProcessed)
                    {
                        isImeProcessed = true;
                        key            = previewKeyUp.RealKey;
                    }
                    else if (key == Key.DeadCharProcessed)
                    {
                        isDeadCharProcessed = true;
                        key = previewKeyUp.RealKey;
                    }

                    KeyEventArgs keyUp = new KeyEventArgs(this, previewKeyUp.UnsafeInputSource, previewKeyUp.Timestamp, key);

                    // Mark the new event as SystemKey as appropriate.
                    if (isSystemKey)
                    {
                        keyUp.MarkSystem();
                    }
                    else if (isImeProcessed)
                    {
                        // Mark the new event as ImeProcessed as appropriate.
                        keyUp.MarkImeProcessed();
                    }
                    else if (isDeadCharProcessed)
                    {
                        keyUp.MarkDeadCharProcessed();
                    }

                    keyUp.RoutedEvent   = Keyboard.KeyUpEvent;
                    keyUp.ScanCode      = previewKeyUp.ScanCode;
                    keyUp.IsExtendedKey = previewKeyUp.IsExtendedKey;
                    e.PushInput(keyUp, e.StagingItem);
                }
            }

            RawKeyboardInputReport keyboardInput = ExtractRawKeyboardInputReport(e, InputManager.InputReportEvent);

            if (keyboardInput != null)
            {
                CheckForDisconnectedFocus();

                if (!e.StagingItem.Input.Handled)
                {
                    // In general, this is where we promote the non-redundant
                    // reported actions to our premier events.
                    RawKeyboardActions actions = GetNonRedundantActions(e);

                    // Raw --> PreviewKeyDown
                    if ((actions & RawKeyboardActions.KeyDown) == RawKeyboardActions.KeyDown)
                    {
                        Key key = (Key)e.StagingItem.GetData(_tagKey);
                        if (key != Key.None)
                        {
                            KeyEventArgs previewKeyDown = new KeyEventArgs(this, keyboardInput.InputSource, keyboardInput.Timestamp, key);
                            ScanCode     scanCode       = (ScanCode)e.StagingItem.GetData(_tagScanCode);
                            previewKeyDown.ScanCode      = scanCode.Code;
                            previewKeyDown.IsExtendedKey = scanCode.IsExtended;
                            if (keyboardInput.IsSystemKey)
                            {
                                previewKeyDown.MarkSystem();
                            }
                            previewKeyDown.RoutedEvent = Keyboard.PreviewKeyDownEvent;
                            e.PushInput(previewKeyDown, e.StagingItem);
                        }
                    }

                    // Raw --> PreviewKeyUp
                    if ((actions & RawKeyboardActions.KeyUp) == RawKeyboardActions.KeyUp)
                    {
                        Key key = (Key)e.StagingItem.GetData(_tagKey);
                        if (key != Key.None)
                        {
                            KeyEventArgs previewKeyUp = new KeyEventArgs(this, keyboardInput.InputSource, keyboardInput.Timestamp, key);
                            ScanCode     scanCode     = (ScanCode)e.StagingItem.GetData(_tagScanCode);
                            previewKeyUp.ScanCode      = scanCode.Code;
                            previewKeyUp.IsExtendedKey = scanCode.IsExtended;
                            if (keyboardInput.IsSystemKey)
                            {
                                previewKeyUp.MarkSystem();
                            }
                            previewKeyUp.RoutedEvent = Keyboard.PreviewKeyUpEvent;
                            e.PushInput(previewKeyUp, e.StagingItem);
                        }
                    }
                }

                // Deactivate
                if ((keyboardInput.Actions & RawKeyboardActions.Deactivate) == RawKeyboardActions.Deactivate)
                {
                    if (IsActive)
                    {
                        _activeSource = null;

                        // Even if handled, a keyboard deactivate results in a lost focus.
                        ChangeFocus(null, e.StagingItem.Input.Timestamp);
                    }
                }
            }
        }
Beispiel #2
0
        private void PostProcessInput(object sender, ProcessInputEventArgs e) 
        {
            // PreviewKeyDown --> KeyDown 
            if(e.StagingItem.Input.RoutedEvent == Keyboard.PreviewKeyDownEvent)
            {
                CheckForDisconnectedFocus();
 
                if(!e.StagingItem.Input.Handled)
                { 
                    KeyEventArgs previewKeyDown = (KeyEventArgs) e.StagingItem.Input; 

                    // Dig out the real key. 
                    bool isSystemKey = false;
                    bool isImeProcessed = false;
                    bool isDeadCharProcessed = false;
                    Key key = previewKeyDown.Key; 
                    if (key == Key.System)
                    { 
                        isSystemKey = true; 
                        key = previewKeyDown.RealKey;
                    } 
                    else if (key == Key.ImeProcessed)
                    {
                        isImeProcessed = true;
                        key = previewKeyDown.RealKey; 
                    }
                    else if (key == Key.DeadCharProcessed) 
                    { 
                        isDeadCharProcessed = true;
                        key = previewKeyDown.RealKey; 
                    }

                    KeyEventArgs keyDown = new KeyEventArgs(this, previewKeyDown.UnsafeInputSource, previewKeyDown.Timestamp, key);
                    keyDown.SetRepeat( previewKeyDown.IsRepeat ); 

                    // Mark the new event as SystemKey as appropriate. 
                    if (isSystemKey) 
                    {
                        keyDown.MarkSystem(); 
                    }
                    else if (isImeProcessed)
                    {
                        // Mark the new event as ImeProcessed as appropriate. 
                        keyDown.MarkImeProcessed();
                    } 
                    else if (isDeadCharProcessed) 
                    {
                        keyDown.MarkDeadCharProcessed(); 
                    }

                    keyDown.RoutedEvent=Keyboard.KeyDownEvent;
                    keyDown.ScanCode = previewKeyDown.ScanCode; 
                    keyDown.IsExtendedKey = previewKeyDown.IsExtendedKey;
                    e.PushInput(keyDown, e.StagingItem); 
                } 
            }
 
            // PreviewKeyUp --> KeyUp
            if(e.StagingItem.Input.RoutedEvent == Keyboard.PreviewKeyUpEvent)
            {
                CheckForDisconnectedFocus(); 

                if(!e.StagingItem.Input.Handled) 
                { 
                    KeyEventArgs previewKeyUp = (KeyEventArgs) e.StagingItem.Input;
 
                    // Dig out the real key.
                    bool isSystemKey = false;
                    bool isImeProcessed = false;
                    bool isDeadCharProcessed = false; 
                    Key key = previewKeyUp.Key;
                    if (key == Key.System) 
                    { 
                        isSystemKey = true;
                        key = previewKeyUp.RealKey; 
                    }
                    else if (key == Key.ImeProcessed)
                    {
                        isImeProcessed = true; 
                        key = previewKeyUp.RealKey;
                    } 
                    else if(key == Key.DeadCharProcessed) 
                    {
                        isDeadCharProcessed = true; 
                        key = previewKeyUp.RealKey;
                    }

                    KeyEventArgs keyUp = new KeyEventArgs(this, previewKeyUp.UnsafeInputSource, previewKeyUp.Timestamp, key); 

                    // Mark the new event as SystemKey as appropriate. 
                    if (isSystemKey) 
                    {
                        keyUp.MarkSystem(); 
                    }
                    else if (isImeProcessed)
                    {
                        // Mark the new event as ImeProcessed as appropriate. 
                        keyUp.MarkImeProcessed();
                    } 
                    else if (isDeadCharProcessed) 
                    {
                        keyUp.MarkDeadCharProcessed(); 
                    }

                    keyUp.RoutedEvent=Keyboard.KeyUpEvent;
                    keyUp.ScanCode = previewKeyUp.ScanCode; 
                    keyUp.IsExtendedKey = previewKeyUp.IsExtendedKey;
                    e.PushInput(keyUp, e.StagingItem); 
                } 
            }
 
            RawKeyboardInputReport keyboardInput = ExtractRawKeyboardInputReport(e, InputManager.InputReportEvent);
            if(keyboardInput != null)
            {
                CheckForDisconnectedFocus(); 

                if(!e.StagingItem.Input.Handled) 
                { 
                    // In general, this is where we promote the non-redundant
                    // reported actions to our premier events. 
                    RawKeyboardActions actions = GetNonRedundantActions(e);

                    // Raw --> PreviewKeyDown
                    if((actions & RawKeyboardActions.KeyDown) == RawKeyboardActions.KeyDown) 
                    {
                        Key key = (Key) e.StagingItem.GetData(_tagKey); 
                        if(key != Key.None) 
                        {
                            KeyEventArgs previewKeyDown = new KeyEventArgs(this, keyboardInput.InputSource, keyboardInput.Timestamp, key); 
                            ScanCode scanCode = (ScanCode)e.StagingItem.GetData(_tagScanCode);
                            previewKeyDown.ScanCode = scanCode.Code;
                            previewKeyDown.IsExtendedKey = scanCode.IsExtended;
                            if (keyboardInput.IsSystemKey) 
                            {
                                previewKeyDown.MarkSystem(); 
                            } 
                            previewKeyDown.RoutedEvent=Keyboard.PreviewKeyDownEvent;
                            e.PushInput(previewKeyDown, e.StagingItem); 
                        }
                    }

                    // Raw --> PreviewKeyUp 
                    if((actions & RawKeyboardActions.KeyUp) == RawKeyboardActions.KeyUp)
                    { 
                        Key key = (Key) e.StagingItem.GetData(_tagKey); 
                        if(key != Key.None)
                        { 
                            KeyEventArgs previewKeyUp = new KeyEventArgs(this, keyboardInput.InputSource, keyboardInput.Timestamp, key);
                            ScanCode scanCode = (ScanCode)e.StagingItem.GetData(_tagScanCode);
                            previewKeyUp.ScanCode = scanCode.Code;
                            previewKeyUp.IsExtendedKey = scanCode.IsExtended; 
                            if (keyboardInput.IsSystemKey)
                            { 
                                previewKeyUp.MarkSystem(); 
                            }
                            previewKeyUp.RoutedEvent=Keyboard.PreviewKeyUpEvent; 
                            e.PushInput(previewKeyUp, e.StagingItem);
                        }
                    }
                } 

                // Deactivate 
                if((keyboardInput.Actions & RawKeyboardActions.Deactivate) == RawKeyboardActions.Deactivate) 
                {
                    if(IsActive) 
                    {
                        _activeSource = null;

                        // Even if handled, a keyboard deactivate results in a lost focus. 
                        ChangeFocus(null, e.StagingItem.Input.Timestamp);
                    } 
                } 
            }
        } 
Beispiel #3
0
        private void PreProcessInput(object sender, PreProcessInputEventArgs e)
        {
            // KeyDown --> Alt Numpad
            //
            // We eat Alt-NumPat keys and handle them by ourselves. Avalon has its own acceralator handler
            // and it may have a corrision with Win32k's AltNumPad handling. As a result, the AltNumPad cache
            // in Win32k's ToUnicodeEx() could be broken.
            //
            if (e.StagingItem.Input.RoutedEvent == Keyboard.KeyDownEvent)
            {
                KeyEventArgs keyArgs = (KeyEventArgs)e.StagingItem.Input;
                if (!keyArgs.Handled)
                {
                    if (!_altNumpadEntryMode)
                    {
                        EnterAltNumpadEntryMode(keyArgs.RealKey);
                    }
                    else
                    {
                        if (HandleAltNumpadEntry(keyArgs.RealKey, keyArgs.ScanCode, keyArgs.IsExtendedKey))
                        {
                            if (_altNumpadcomposition == null)
                            {
                                _altNumpadcomposition = new TextComposition(_inputManager, (IInputElement)keyArgs.Source, "", TextCompositionAutoComplete.Off, keyArgs.Device);
                                keyArgs.Handled       = UnsafeStartComposition(_altNumpadcomposition);
                            }
                            else
                            {
                                _altNumpadcomposition.ClearTexts();
                                keyArgs.Handled = UnsafeUpdateComposition(_altNumpadcomposition);
                            }

                            // We ate this key for AltNumPad entry. None will be able to handle this.
                            e.Cancel();
                        }
                        else
                        {
                            // alt numpad entry was reset so composition needs to be finalized.
                            if (_altNumpadcomposition != null)
                            {
                                _altNumpadcomposition.ClearTexts();
                                _altNumpadcomposition.Complete();
                                ClearAltnumpadComposition();
                            }
                        }
                    }
                }
            }

            if (e.StagingItem.Input.RoutedEvent == Keyboard.PreviewKeyDownEvent)
            {
                KeyEventArgs keyArgs = (KeyEventArgs)e.StagingItem.Input;
                //This makes sure that deadChar's do not get handled in commands
                //As a result they are unhandled KeyDown events that are sent to translate input.
                //
                if (!keyArgs.Handled &&
                    (_deadCharTextComposition != null) &&
                    (_deadCharTextComposition.Stage == TextCompositionStage.Started))
                {
                    keyArgs.MarkDeadCharProcessed();
                }
            }
        }