Exemple #1
0
        private void AddKeyModifiers(object jsEventArg)
        {
#if MIGRATION
            ModifierKeys keyModifiers = ModifierKeys.None;
#else
            VirtualKeyModifiers keyModifiers = VirtualKeyModifiers.None;
#endif
            if (Convert.ToBoolean(CSHTML5.Interop.ExecuteJavaScript("$0.shiftKey || false", jsEventArg))) //Note: we use "||" because the value "shiftKey" may be null or undefined. For more information on "||", read: https://stackoverflow.com/questions/476436/is-there-a-null-coalescing-operator-in-javascript
            {
#if MIGRATION
                keyModifiers = keyModifiers | ModifierKeys.Shift;
#else
                keyModifiers = keyModifiers | VirtualKeyModifiers.Shift;
#endif
            }
            if (Convert.ToBoolean(CSHTML5.Interop.ExecuteJavaScript("$0.altKey || false", jsEventArg)))
            {
#if MIGRATION
                keyModifiers = keyModifiers | ModifierKeys.Alt;
#else
                keyModifiers = keyModifiers | VirtualKeyModifiers.Menu;
#endif
            }
            if (Convert.ToBoolean(CSHTML5.Interop.ExecuteJavaScript("$0.ctrlKey || false", jsEventArg)))
            {
#if MIGRATION
                keyModifiers = keyModifiers | ModifierKeys.Control;
#else
                keyModifiers = keyModifiers | VirtualKeyModifiers.Control;
#endif
            }
            KeyModifiers = keyModifiers;
        }
        private void LookForOemModifiers(char c, uint virtualKey, VirtualKeyModifiers virtualKeyModifiers)
        {
            // These are flags but we can only search one at a time here.  If both are present it's not
            // possible to distinguish one from the others
            var regular  = virtualKeyModifiers & VirtualKeyModifiers.Regular;
            var extended = virtualKeyModifiers & VirtualKeyModifiers.Extended;

            switch (extended)
            {
            case VirtualKeyModifiers.Oem1:
                if (!_lookedForOem1ModifierVirtualKey)
                {
                    _lookedForOem1ModifierVirtualKey = true;
                    _keyboard.Oem1ModifierVirtualKey = LookForOemModifiersSingle(c, virtualKey, regular);
                }
                break;

            case VirtualKeyModifiers.Oem2:
                if (!_lookedForOem2ModifierVirtualKey)
                {
                    _lookedForOem2ModifierVirtualKey = true;
                    _keyboard.Oem2ModifierVirtualKey = LookForOemModifiersSingle(c, virtualKey, regular);
                }
                break;
            }
        }
 public static T AddKeyboardAccelerator <T>(this T u, VirtualKey key, VirtualKeyModifiers modifiers) where T : UIElement
 {
     u.KeyboardAccelerators.Add(new KeyboardAccelerator {
         Key = key, Modifiers = modifiers
     });
     return(u);
 }
        protected override void OnKeyUp(KeyRoutedEventArgs e)
        {
            base.OnKeyUp(e);
            if (!IsControl(e.Key) &&
                !IsShift(e.Key))
            {
                Keys.Remove(e.Key);
            }
            //CurrentKey = e.Key;
            KeyState = CoreVirtualKeyStates.None;
            Execute(e);
            if (Keys.Count > 0)
            {
                KeyState = CoreVirtualKeyStates.Down;
            }
            if (IsControl(e.Key))
            {
                KeyModifiers ^= VirtualKeyModifiers.Control;
            }
            else if (IsShift(e.Key))
            {
                KeyModifiers ^= VirtualKeyModifiers.Shift;
            }

            if (Keys.Count > 0)
            {
                CurrentKey = Keys.Last();
            }
            else
            {
                CurrentKey = VirtualKey.None;
            }
        }
Exemple #5
0
 public static IEngineConfigurationBuilder WithPanOnKeyAndMouseMove(
     this IEngineConfigurationBuilder builder,
     VirtualKeyModifiers modifier = VirtualKeyModifiers.Control)
 {
     builder.Engine.AddFeature(new PanMapEngineFeature(modifier));
     return(builder);
 }
        protected override void OnKeyDown(KeyRoutedEventArgs e)
        {
            base.OnKeyDown(e);
            EditMode = true;
            settingbutton.IsChecked = false;
            #region Keyboard Commands
            KeyState = CoreVirtualKeyStates.Down;

            if (IsControl(e.Key))
            {
                KeyModifiers |= VirtualKeyModifiers.Control;
            }
            else if (IsShift(e.Key))
            {
                KeyModifiers |= VirtualKeyModifiers.Shift;
            }
            else
            {
                CurrentKey = e.Key;
                if (!Keys.Contains(e.Key))
                {
                    Keys.Add(e.Key);
                }
            }
            Execute(e);
            //e.Handled = true;
            #endregion
        }
 private bool TryGetShortcut(VirtualKeyModifiers modifiers, VirtualKey key, out Shortcut shortcut)
 {
     if (key is VirtualKey.Control or VirtualKey.LeftControl or VirtualKey.RightControl)
     {
         shortcut = null;
         return(false);
     }
Exemple #8
0
        private bool TryGetShortcut(VirtualKeyModifiers modifiers, VirtualKey key, out Shortcut shortcut)
        {
            if (key == VirtualKey.Control || key == VirtualKey.LeftControl || key == VirtualKey.RightControl)
            {
                shortcut = null;
                return(false);
            }
            else if (key == VirtualKey.Menu || key == VirtualKey.LeftMenu || key == VirtualKey.RightMenu)
            {
                shortcut = null;
                return(false);
            }
            else if (key == VirtualKey.Shift || key == VirtualKey.LeftShift || key == VirtualKey.RightShift)
            {
                shortcut = null;
                return(false);
            }

            if (modifiers == VirtualKeyModifiers.None && (key < VirtualKey.F1 || key > VirtualKey.F24))
            {
                shortcut = null;
                return(false);
            }

            shortcut = new Shortcut(modifiers, key);
            return(Enum.IsDefined(typeof(VirtualKey), key));
        }
        internal PointerRoutedEventArgs(
            double timestamp,
            uint pointerId,
            PointerDeviceType pointerType,
            Point absolutePosition,
            bool isInContact,
            WindowManagerInterop.HtmlPointerButtonsState buttons,
            WindowManagerInterop.HtmlPointerButtonUpdate buttonUpdate,
            VirtualKeyModifiers keys,
            double pressure,
            UIElement source,
            bool canBubbleNatively)
            : this()
        {
            _timestamp        = timestamp;
            _absolutePosition = absolutePosition;
            _buttons          = buttons;
            _buttonUpdate     = buttonUpdate;
            _pressure         = pressure;

            FrameId           = ToFrameId(timestamp);
            Pointer           = new Pointer(pointerId, pointerType, isInContact, isInRange: true);
            KeyModifiers      = keys;
            OriginalSource    = source;
            CanBubbleNatively = canBubbleNatively;
        }
Exemple #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:GrapeCity.Windows.SpreadSheet.UI.KeyStroke" /> structure
 /// with the specified <see cref="T:System.Windows.Input.Key" />, <see cref="T:System.Windows.Input.ModifierKeys" />,
 /// and a value that indicates whether this <see cref="T:GrapeCity.Windows.SpreadSheet.UI.KeyStroke" /> is active on the key
 /// release.
 /// </summary>
 /// <param name="keyCode">
 /// The key code defined by this <see cref="T:GrapeCity.Windows.SpreadSheet.UI.KeyStroke" /> structure.
 /// </param>
 /// <param name="modifiers">
 /// The modifier keys defined by this <see cref="T:GrapeCity.Windows.SpreadSheet.UI.KeyStroke" /> structure.
 /// </param>
 /// <param name="onKeyRelease">
 /// A value that indicates whether the <see cref="T:GrapeCity.Windows.SpreadSheet.UI.KeyStroke" /> is active on the key release.
 /// </param>
 public KeyStroke(VirtualKey keyCode, VirtualKeyModifiers modifiers, bool onKeyRelease)
 {
     this         = new KeyStroke();
     KeyChar      = '\0';
     KeyCode      = keyCode;
     Modifiers    = modifiers;
     OnKeyRelease = onKeyRelease;
 }
Exemple #11
0
 private void TryRemoveAccelerator(VirtualKey k, VirtualKeyModifiers m)
 {
     if (TryFindAccelerator(k, m, out KeyboardAccelerator acc))
     {
         return;
     }
     acc.Invoked -= KeyboardAccelerator_Invoked;
     EditorCanvas.KeyboardAccelerators.Remove(acc);
 }
Exemple #12
0
        private static bool CheckModifier(VirtualKeyModifiers current, VirtualKeyModifiers requested, VirtualKey key)
        {
            if ((current & requested) == requested)
            {
                return((Window.Current.CoreWindow.GetKeyState(key) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down);
            }

            return(true);
        }
        private InvokedShortcut Process(VirtualKeyModifiers modifiers, VirtualKey key)
        {
            var shortcut = new Shortcut(modifiers, key);

            if (_commands.TryGetValue(shortcut, out var value))
            {
                return(new InvokedShortcut(modifiers, key, value));
            }

            return(new InvokedShortcut(VirtualKeyModifiers.None, VirtualKey.None, new ShortcutCommand[0]));
        }
Exemple #14
0
        private void CreateKeyboardAccelerator(VirtualKey key, VirtualKeyModifiers modifiers = VirtualKeyModifiers.Control)
        {
            if (ApiInfo.CanUseAccelerators)
            {
                var accelerator = new KeyboardAccelerator {
                    Modifiers = modifiers, Key = key, ScopeOwner = this
                };
                accelerator.Invoked += FlyoutAccelerator_Invoked;

                KeyboardAccelerators.Add(accelerator);
            }
        }
Exemple #15
0
        public bool PointerPressed(ICanvasResourceCreatorWithDpi creator, VirtualKeyModifiers keyModifiers, PointerPoint pointerPoint)
        {
            /*var position = pointerPoint.Position;
             *
             * seeker.MoveTo(position.ToVector2());*/

            /*var position = pointerPoint.Position;
             * var tower = new LaserTower(enemyProvider, position.ToVector2(), Colors.Yellow, 0.7d, 150.0d);
             *
             * tower.CreateResources(creator, CanvasCreateResourcesReason.FirstTime);
             * scene.Children.Add(tower);*/

            return(true);
        }
Exemple #16
0
 private bool TryFindAccelerator(VirtualKey k, VirtualKeyModifiers m, out KeyboardAccelerator acc)
 {
     foreach (var ka in EditorCanvas.KeyboardAccelerators)
     {
         if (ka.Key != k || ka.Modifiers != m)
         {
             continue;
         }
         acc = ka;
         return(true);
     }
     acc = null;
     return(false);
 }
        /// <summary>
        /// Simple mechanism for getting the text for the given virtual key code and the specified
        /// modifiers
        ///
        /// This method is intended to leave the values in the keyboard state array set that are
        /// set before calling.  It will clear out the keyboard state after calling though
        /// </summary>
        private bool TryGetText(uint virtualKey, VirtualKeyModifiers virtualKeyModifiers, out string text, out bool isDeadKey)
        {
            var scanCode = NativeMethods.MapVirtualKeyEx(virtualKey, 0, _keyboardId);

            if (scanCode == 0)
            {
                text      = String.Empty;
                isDeadKey = false;
                return(false);
            }

            try
            {
                _keyboardState.SetShiftState(virtualKeyModifiers);
                _normalBuilder.Length = 0;
                var value = NativeMethods.ToUnicodeEx(
                    virtualKey,
                    scanCode,
                    _keyboardState.State,
                    _normalBuilder,
                    _normalBuilder.Capacity,
                    0,
                    _keyboardId);
                if (value < 0)
                {
                    // It's a dead key. Make sure to clear out the cached state
                    ClearKeyboardBuffer();
                    isDeadKey = true;
                    text      = String.Empty;
                    return(false);
                }
                else if (value > 0)
                {
                    isDeadKey = false;
                    text      = _normalBuilder.ToString();
                    return(true);
                }
                else
                {
                    isDeadKey = false;
                    text      = String.Empty;
                    return(false);
                }
            }
            finally
            {
                _keyboardState.Clear();
            }
        }
Exemple #18
0
        internal void AddKeyModifiersAndUpdateDocumentValue(object jsEventArg)
        {
#if MIGRATION
            ModifierKeys keyModifiers = ModifierKeys.None;
#else
            VirtualKeyModifiers keyModifiers = VirtualKeyModifiers.None;
#endif
            if (Convert.ToBoolean(Interop.ExecuteJavaScript("$0.shiftKey || false", jsEventArg))) //Note: we use "||" because the value "shiftKey" may be null or undefined. For more information on "||", read: https://stackoverflow.com/questions/476436/is-there-a-null-coalescing-operator-in-javascript
            {
#if MIGRATION
                keyModifiers = keyModifiers | ModifierKeys.Shift;
#else
                keyModifiers = keyModifiers | VirtualKeyModifiers.Shift;
#endif
            }
            if (Convert.ToBoolean(Interop.ExecuteJavaScript("$0.altKey || false", jsEventArg)))
            {
#if MIGRATION
                keyModifiers = keyModifiers | ModifierKeys.Alt;
#else
                keyModifiers = keyModifiers | VirtualKeyModifiers.Menu;
#endif
            }
            if (Convert.ToBoolean(Interop.ExecuteJavaScript("$0.ctrlKey || false", jsEventArg)))
            {
#if MIGRATION
                keyModifiers = keyModifiers | ModifierKeys.Control;
#else
                keyModifiers = keyModifiers | VirtualKeyModifiers.Control;
#endif
            }
            KeyModifiers = keyModifiers;

            //Refreshing the value for key modifiers in the html document to ensure the value is correct when sending the event (For cases where the users use Keyboard.Modifiers inside the event's handler).
            //Note: this is mandatory because we have no way to be sure the events document.onkeyup and document.onkeydown are thrown before the one that made us arrive here.
            Interop.ExecuteJavaScript(@"document.refreshKeyModifiers($0);", jsEventArg);

            /*
             * if (!CSHTML5.Interop.IsRunningInTheSimulator)
             * {
             *  CSHTML5.Interop.ExecuteJavaScript(@"document.refreshKeyModifiers($0);", jsEventArg);
             * }
             * else
             * {
             *  dynamic document = INTERNAL_Simulator.HtmlDocument;
             *  document.Invoke("refreshKeyModifiers", jsEventArg);
             * }
             */
        }
Exemple #19
0
        private void TryAddAccelerator(VirtualKey k, VirtualKeyModifiers m)
        {
            if (TryFindAccelerator(k, m, out KeyboardAccelerator _))
            {
                return;
            }
            var acc = new Windows.UI.Xaml.Input.KeyboardAccelerator
            {
                Key       = k,
                Modifiers = m
            };

            acc.Invoked += KeyboardAccelerator_Invoked;
            EditorCanvas.KeyboardAccelerators.Add(acc);
        }
Exemple #20
0
        bool IVirtualKeyboard.TryMapChar(char c, out uint virtualKey, out VirtualKeyModifiers virtualKeyModifiers)
        {
            foreach (var pair in _keyMap)
            {
                if (pair.Value[0] == c)
                {
                    virtualKey          = (uint)KeyInterop.VirtualKeyFromKey(pair.Key.Key);
                    virtualKeyModifiers = pair.Key.Modifiers;
                    return(true);
                }
            }

            virtualKey          = 0;
            virtualKeyModifiers = VirtualKeyModifiers.None;
            return(false);
        }
        private void Element_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            switch (e.Key)
            {
            case VirtualKey.Control:
                controlPressed = true;
                return;

            case VirtualKey.Menu:
            case VirtualKey.LeftMenu:
            case VirtualKey.RightMenu:
                menuPressed = true;
                return;

            case VirtualKey.Shift:
            case VirtualKey.LeftShift:
            case VirtualKey.RightShift:
                shiftPressed = true;
                return;
            }

            VirtualKeyModifiers modifiers = 0;

            if (controlPressed)
            {
                modifiers |= VirtualKeyModifiers.Control;
            }
            if (menuPressed)
            {
                modifiers |= VirtualKeyModifiers.Menu;
            }
            if (shiftPressed)
            {
                modifiers |= VirtualKeyModifiers.Shift;
            }

            foreach (var shortcutHandler in shortcutHandlers)
            {
                if (shortcutHandler.VirtualKeyModifiers == modifiers &&
                    shortcutHandler.VirtualKey == e.Key)
                {
                    shortcutHandler.Handler(this, e);
                }
            }
        }
Exemple #22
0
        bool IVirtualKeyboard.TryGetText(uint virtualKey, VirtualKeyModifiers virtualKeyModifiers, out string text, out bool isDeadKey)
        {
            try
            {
                if (VirtualKeyModifiers.Oem1 == (virtualKeyModifiers & VirtualKeyModifiers.Oem1))
                {
                    if (!Oem1Modifier.HasValue)
                    {
                        text      = String.Empty;
                        isDeadKey = false;
                        return(false);
                    }
                }

                if (Oem1Modifier.HasValue && KeyboardState.IsKeySet(Oem1Modifier.Value))
                {
                    virtualKeyModifiers |= VirtualKeyModifiers.Oem1;
                }

                if (VirtualKeyModifiers.Oem2 == (virtualKeyModifiers & VirtualKeyModifiers.Oem2))
                {
                    if (!Oem2Modifier.HasValue)
                    {
                        text      = String.Empty;
                        isDeadKey = false;
                        return(false);
                    }
                }

                if (Oem2Modifier.HasValue && KeyboardState.IsKeySet(Oem2Modifier.Value))
                {
                    virtualKeyModifiers |= VirtualKeyModifiers.Oem2;
                }

                var key      = KeyInterop.KeyFromVirtualKey((int)virtualKey);
                var keyState = new KeyState(key, virtualKeyModifiers);
                isDeadKey = false;
                return(_keyMap.TryGetValue(keyState, out text));
            }
            finally
            {
                _keyboardState.Clear();
            }
        }
        /// <summary>
        /// Map the given char to a virtual key code and the associated necessary modifier keys for
        /// the provided keyboard layout
        /// </summary>
        private bool TryMapChar(char c, out uint virtualKeyCode, out VirtualKeyModifiers virtualKeyModifiers)
        {
            var res = NativeMethods.VkKeyScanEx(c, _keyboardId);

            // The virtual key code is the low byte and the shift state is the high byte
            var virtualKey = res & 0xff;
            var state      = ((res >> 8) & 0xff);

            if (virtualKey == -1 || state == -1)
            {
                virtualKeyCode      = 0;
                virtualKeyModifiers = VirtualKeyModifiers.None;
                return(false);
            }

            virtualKeyCode      = (uint)virtualKey;
            virtualKeyModifiers = (VirtualKeyModifiers)state;
            return(true);
        }
        /// <summary>
        /// Creates a platform-independent instance of <see cref="PointerPoint"/> class from WinRT-specific objects.
        /// </summary>
        /// <param name="type">The pointer event type.</param>
        /// <param name="modifiers">The pressed modifier keys.</param>
        /// <param name="point">The WinRT-specific instance of pointer point.</param>
        /// <returns>An instance of <see cref="PointerPoint"/> class.</returns>
        private void CreateAndAddPoint(PointerEventType type, VirtualKeyModifiers modifiers, global::Windows.UI.Input.PointerPoint point)
        {
            if (point == null)
            {
                throw new ArgumentNullException("point");
            }

            var position    = point.Position;
            var properties  = point.Properties;
            var contactRect = properties.ContactRect;

            var result = new PointerPoint
            {
                EventType              = type,
                DeviceType             = GetDeviceType(point.PointerDevice.PointerDeviceType),
                KeyModifiers           = GetKeyModifiers(modifiers),
                PointerId              = point.PointerId,
                Position               = new Vector2((float)position.X / windowSize.Width, (float)position.Y / windowSize.Height),
                Timestamp              = point.Timestamp,
                ContactRect            = new RectangleF((float)contactRect.X / windowSize.Width, (float)contactRect.Y / windowSize.Height, (float)contactRect.Width / windowSize.Width, (float)contactRect.Height / windowSize.Height),
                IsBarrelButtonPressed  = properties.IsBarrelButtonPressed,
                IsCanceled             = properties.IsCanceled,
                IsEraser               = properties.IsEraser,
                IsHorizontalMouseWheel = properties.IsHorizontalMouseWheel,
                IsInRange              = properties.IsInRange,
                IsInverted             = properties.IsInverted,
                IsLeftButtonPressed    = properties.IsLeftButtonPressed,
                IsMiddleButtonPressed  = properties.IsMiddleButtonPressed,
                IsPrimary              = properties.IsPrimary,
                IsRightButtonPressed   = properties.IsRightButtonPressed,
                IsXButton1Pressed      = properties.IsXButton1Pressed,
                IsXButton2Pressed      = properties.IsXButton2Pressed,
                MouseWheelDelta        = properties.MouseWheelDelta,
                Orientation            = properties.Orientation,
                TouchConfidence        = properties.TouchConfidence,
                Twist             = properties.Twist,
                XTilt             = properties.XTilt,
                YTilt             = properties.YTilt,
                PointerUpdateKind = GetPointerUpdateKind(properties.PointerUpdateKind)
            };

            manager.AddPointerEvent(ref result);
        }
        protected override void OnKeyDown(KeyRoutedEventArgs e)
        {
            e.Handled = true;

            var key = e.Key;

            var isModifier = false;
            var modifier   = VirtualKeyModifiers.None;

            if (key == VirtualKey.Control)
            {
                isModifier = true;
                modifier   = VirtualKeyModifiers.Control;
            }
            else if (key == VirtualKey.Menu)
            {
                isModifier = true;
                modifier   = VirtualKeyModifiers.Menu;
            }
            else if (key == VirtualKey.LeftWindows || key == VirtualKey.RightWindows)
            {
                isModifier = true;
                modifier   = VirtualKeyModifiers.Windows;
            }
            else if (key == VirtualKey.Shift)
            {
                isModifier = true;
                modifier   = VirtualKeyModifiers.Shift;
            }

            if (isModifier)
            {
                _modifiers |= modifier;
                OnHotkeyChanged();
            }
            else if (_key == VirtualKey.None)
            {
                _key = key;
                OnHotkeyChanged();
            }
        }
Exemple #26
0
        private async void image_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            //Logic to call zoom in or out functions based on user action
            if (isDoubleTapped)
            {
                isDoubleTapped = false;
                VirtualKeyModifiers vkm = e.KeyModifiers;
                if ((vkm & VirtualKeyModifiers.Shift) == VirtualKeyModifiers.Shift)
                {
                    //Shift+double tap user action should cause zoom out of the image
                    isZoomIn = false;
                }
                else
                {
                    //Simple double tap user action should cause zoom in of the image
                    isZoomIn = true;
                }

                await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, ZoomInOrOut);
            }
        }
        private uint?LookForOemModifiersSingle(char c, uint virtualKey, VirtualKeyModifiers regularKeyModifiers)
        {
            var target = c.ToString();

            _keyboard.Clear();
            foreach (var code in _possibleModifierVirtualKey.Value)
            {
                // Set the keyboard state
                _keyboard.SetKey(code);

                // Now try to get the text value with the previous key down
                string text;
                bool   unused;
                if (_virtualKeyboard.TryGetText(virtualKey, regularKeyModifiers, out text, out unused) && text == target)
                {
                    return(code);
                }
            }

            return(null);
        }
Exemple #28
0
 void OnKeyUp(object sender, KeyRoutedEventArgs e)
 {
     UpdateCursorType();
     if (!IsEditing)
     {
         bool       flag;
         bool       flag2;
         VirtualKey keyCode = e.Key;
         KeyboardHelper.GetMetaKeyState(out flag, out flag2);
         VirtualKeyModifiers none = VirtualKeyModifiers.None;
         if (flag2)
         {
             none |= VirtualKeyModifiers.Control;
         }
         if (flag)
         {
             none |= VirtualKeyModifiers.None | VirtualKeyModifiers.Shift;
         }
         KeyStroke stroke = new KeyStroke(keyCode, none, true);
         if (KeyMap.ContainsKey(stroke))
         {
             SpreadAction action = KeyMap[stroke];
             if (action != null)
             {
                 ActionEventArgs args = new ActionEventArgs();
                 action(this, args);
                 if (args.Handled)
                 {
                     e.Handled = true;
                 }
             }
         }
     }
     if (IsDragDropping)
     {
         SwitchDragDropIndicator();
     }
 }
        /// <summary>
        /// Maps from WinRT-specific key modifiers enumeration to platform-independent flags.
        /// </summary>
        /// <param name="modifiers">WinRT-specific key modifiers.</param>
        /// <returns>Platform-independent flags.</returns>
        private static KeyModifiers GetKeyModifiers(VirtualKeyModifiers modifiers)
        {
            var result = KeyModifiers.None;

            if (modifiers.HasFlag(VirtualKeyModifiers.Control))
            {
                result |= KeyModifiers.Control;
            }
            if (modifiers.HasFlag(VirtualKeyModifiers.Menu))
            {
                result |= KeyModifiers.Menu;
            }
            if (modifiers.HasFlag(VirtualKeyModifiers.Shift))
            {
                result |= KeyModifiers.Shift;
            }
            if (modifiers.HasFlag(VirtualKeyModifiers.Windows))
            {
                result |= KeyModifiers.Windows;
            }

            return(result);
        }
        internal PointerRoutedEventArgs(
            double timestamp,
            uint pointerId,
            PointerDeviceType pointerType,
            Point absolutePosition,
            bool isInContact,
            VirtualKey button,
            VirtualKeyModifiers keys,
            PointerUpdateKind updateKind,
            UIElement source,
            bool canBubbleNatively)
            : this()
        {
            _timestamp        = timestamp;
            _absolutePosition = absolutePosition;
            _button           = button;
            _updateKind       = updateKind;

            FrameId           = ToFrameId(timestamp);
            Pointer           = new Pointer(pointerId, pointerType, isInContact, isInRange: true);
            KeyModifiers      = keys;
            OriginalSource    = source;
            CanBubbleNatively = canBubbleNatively;
        }
        /// <summary>
        /// Maps from WinRT-specific key modifiers enumeration to platform-independent flags.
        /// </summary>
        /// <param name="modifiers">WinRT-specific key modifiers.</param>
        /// <returns>Platform-independent flags.</returns>
        private static KeyModifiers GetKeyModifiers(VirtualKeyModifiers modifiers)
        {
            var result = KeyModifiers.None;

            if (modifiers.HasFlag(VirtualKeyModifiers.Control)) result |= KeyModifiers.Control;
            if (modifiers.HasFlag(VirtualKeyModifiers.Menu)) result |= KeyModifiers.Menu;
            if (modifiers.HasFlag(VirtualKeyModifiers.Shift)) result |= KeyModifiers.Shift;
            if (modifiers.HasFlag(VirtualKeyModifiers.Windows)) result |= KeyModifiers.Windows;

            return result;
        }
        /// <summary>
        /// Creates a platform-independent instance of <see cref="PointerPoint"/> class from WinRT-specific objects.
        /// </summary>
        /// <param name="type">The pointer event type.</param>
        /// <param name="modifiers">The pressed modifier keys.</param>
        /// <param name="point">The WinRT-specific instance of pointer point.</param>
        /// <returns>An instance of <see cref="PointerPoint"/> class.</returns>
        private void CreateAndAddPoint(PointerEventType type, VirtualKeyModifiers modifiers, global::Windows.UI.Input.PointerPoint point)
        {
            if (point == null) throw new ArgumentNullException("point");

            var position = point.Position;
            var properties = point.Properties;
            var contactRect = properties.ContactRect;

            var result = new PointerPoint
                        {
                            EventType = type,
                            DeviceType = GetDeviceType(point.PointerDevice.PointerDeviceType),
                            KeyModifiers = GetKeyModifiers(modifiers),
                            PointerId = point.PointerId,
                            Position = new Vector2((float)position.X / windowSize.Width, (float)position.Y / windowSize.Height),
                            Timestamp = point.Timestamp,
                            ContactRect = new RectangleF((float)contactRect.X / windowSize.Width, (float)contactRect.Y / windowSize.Height, (float)contactRect.Width / windowSize.Width, (float)contactRect.Height / windowSize.Height),
                            IsBarrelButtonPressed = properties.IsBarrelButtonPressed,
                            IsCanceled = properties.IsCanceled,
                            IsEraser = properties.IsEraser,
                            IsHorizontalMouseWheel = properties.IsHorizontalMouseWheel,
                            IsInRange = properties.IsInRange,
                            IsInverted = properties.IsInverted,
                            IsLeftButtonPressed = properties.IsLeftButtonPressed,
                            IsMiddleButtonPressed = properties.IsMiddleButtonPressed,
                            IsPrimary = properties.IsPrimary,
                            IsRightButtonPressed = properties.IsRightButtonPressed,
                            IsXButton1Pressed = properties.IsXButton1Pressed,
                            IsXButton2Pressed = properties.IsXButton2Pressed,
                            MouseWheelDelta = properties.MouseWheelDelta,
                            Orientation = properties.Orientation,
                            TouchConfidence = properties.TouchConfidence,
                            Twist = properties.Twist,
                            XTilt = properties.XTilt,
                            YTilt = properties.YTilt,
                            PointerUpdateKind = GetPointerUpdateKind(properties.PointerUpdateKind)
                        };

            manager.AddPointerEvent(ref result);
        }
 bool IVirtualKeyboard.TryMapChar(char c, out uint virtualKey, out VirtualKeyModifiers virtualKeyModifiers)
 {
     return TryMapChar(c, out virtualKey, out virtualKeyModifiers);
 }
 bool IVirtualKeyboard.TryGetText(uint virtualKey, VirtualKeyModifiers virtualKeyModifiers, out string text, out bool isDeadKey)
 {
     return TryGetText(virtualKey, virtualKeyModifiers, out text, out isDeadKey);
 }
        /// <summary>
        /// Map the given char to a virtual key code and the associated necessary modifier keys for
        /// the provided keyboard layout
        /// </summary>
        private bool TryMapChar(char c, out uint virtualKeyCode, out VirtualKeyModifiers virtualKeyModifiers)
        {
            var res = NativeMethods.VkKeyScanEx(c, _keyboardId);

            // The virtual key code is the low byte and the shift state is the high byte
            var virtualKey = res & 0xff;
            var state = ((res >> 8) & 0xff);
            if (virtualKey == -1 || state == -1)
            {
                virtualKeyCode = 0;
                virtualKeyModifiers = VirtualKeyModifiers.None;
                return false;
            }

            virtualKeyCode = (uint)virtualKey;
            virtualKeyModifiers = (VirtualKeyModifiers)state;
            return true;
        }
Exemple #36
0
 internal KeyState(Key key, VirtualKeyModifiers modifiers)
 {
     Key = key;
     Modifiers = modifiers;
 }
 private void LookForOemModifiers(char c, uint virtualKey, VirtualKeyModifiers virtualKeyModifiers)
 {
     // These are flags but we can only search one at a time here.  If both are present it's not
     // possible to distinguish one from the others
     var regular = virtualKeyModifiers & VirtualKeyModifiers.Regular;
     var extended = virtualKeyModifiers & VirtualKeyModifiers.Extended;
     switch (extended)
     {
         case VirtualKeyModifiers.Oem1:
             if (!_lookedForOem1ModifierVirtualKey)
             {
                 _lookedForOem1ModifierVirtualKey = true;
                 _keyboard.Oem1ModifierVirtualKey = LookForOemModifiersSingle(c, virtualKey, regular);
             }
             break;
         case VirtualKeyModifiers.Oem2:
             if (!_lookedForOem2ModifierVirtualKey)
             {
                 _lookedForOem2ModifierVirtualKey = true;
                 _keyboard.Oem2ModifierVirtualKey = LookForOemModifiersSingle(c, virtualKey, regular);
             }
             break;
     }
 }
        private uint? LookForOemModifiersSingle(char c, uint virtualKey, VirtualKeyModifiers regularKeyModifiers)
        {
            var target = c.ToString();
            _keyboard.Clear();
            foreach (var code in _possibleModifierVirtualKey.Value)
            {
                // Set the keyboard state
                _keyboard.SetKey(code);

                // Now try to get the text value with the previous key down
                string text;
                bool unused;
                if (_virtualKeyboard.TryGetText(virtualKey, regularKeyModifiers, out text, out unused) && text == target)
                {
                    return code;
                }
            }

            return null;
        }
        /// <summary>
        /// Simple mechanism for getting the text for the given virtual key code and the specified
        /// modifiers
        ///
        /// This method is intended to leave the values in the keyboard state array set that are
        /// set before calling.  It will clear out the keyboard state after calling though
        /// </summary>
        private bool TryGetText(uint virtualKey, VirtualKeyModifiers virtualKeyModifiers, out string text, out bool isDeadKey)
        {
            var scanCode = NativeMethods.MapVirtualKeyEx(virtualKey, 0, _keyboardId);
            if (scanCode == 0)
            {
                text = String.Empty;
                isDeadKey = false;
                return false;
            }

            try
            {
                _keyboardState.SetShiftState(virtualKeyModifiers);
                _normalBuilder.Length = 0;
                var value = NativeMethods.ToUnicodeEx(
                    virtualKey,
                    scanCode,
                    _keyboardState.State,
                    _normalBuilder,
                    _normalBuilder.Capacity,
                    0,
                    _keyboardId);
                if (value < 0)
                {
                    // It's a dead key. Make sure to clear out the cached state
                    ClearKeyboardBuffer();
                    isDeadKey = true;
                    text = String.Empty;
                    return false;
                }
                else if (value > 0)
                {
                    isDeadKey = false;
                    text = _normalBuilder.ToString();
                    return true;
                }
                else
                {
                    isDeadKey = false;
                    text = String.Empty;
                    return false;
                }
            }
            finally
            {
                _keyboardState.Clear();
            }
        }
Exemple #40
0
 internal KeyState(Key key, ModifierKeys modifierKeys)
 {
     Key = key;
     Modifiers = GetVirtualKeyModifiers(modifierKeys);
 }