当前位置: 首页>>代码示例>>C#>>正文


C# VirtualKey.IsModifier方法代码示例

本文整理汇总了C#中VirtualKey.IsModifier方法的典型用法代码示例。如果您正苦于以下问题:C# VirtualKey.IsModifier方法的具体用法?C# VirtualKey.IsModifier怎么用?C# VirtualKey.IsModifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VirtualKey的用法示例。


在下文中一共展示了VirtualKey.IsModifier方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckKeyCombination

        private MatchKind CheckKeyCombination(KeyCombination combination, VirtualKey keyAdded, KeyCombination precedingCombination = null)
        {
            // A key gesture is defined by either explicit modifier keys in both combinations
            // or no modifiers specified for second combination,
            // but then the second combination works with either no modifiers or same modifiers as the first.

            // A gesture is rejected if a combination with unrecognized non-modifier key is used.
            var downState = CoreVirtualKeyStates.Down;
            var ctrl = (this.window.CoreWindow.GetKeyState(VirtualKey.Control) & downState) == downState;
            var alt = (this.window.CoreWindow.GetKeyState(VirtualKey.Menu) & downState) == downState;
            var shift = (this.window.CoreWindow.GetKeyState(VirtualKey.Shift) & downState) == downState;

            if (!keyAdded.IsModifier())
            {
                if (combination.Contains(keyAdded))
                {
                    foreach (var key in combination)
                    {
                        if (key == keyAdded)
                        {
                            continue;
                        }


                        if ((this.window.CoreWindow.GetKeyState(key) & downState) != downState)
                        {
                            // Missing some modifier key
                            return MatchKind.Mismatch;
                        }
                    }

                    // All the keys matched!

                    // Reject if found additional modifiers pressed
                    if (ctrl &&
                        (!combination.Contains(VirtualKey.Control) &&
                        (precedingCombination == null || !precedingCombination.Contains(VirtualKey.Control))) ||
                        alt &&
                        (!combination.Contains(VirtualKey.Menu) ||
                        (precedingCombination == null || !precedingCombination.Contains(VirtualKey.Menu))) ||
                        shift &&
                        (!combination.Contains(VirtualKey.Shift) ||
                        (precedingCombination == null || !precedingCombination.Contains(VirtualKey.Shift))))
                    {
                        return MatchKind.Mismatch;
                    }

                    return MatchKind.Match;
                }
                else
                {
                    // An invalid non-modifier key was pressed
                    return MatchKind.Mismatch;
                }
            }
            else
            {
                // Only recognizing combinations when a non-modifier key is pressed
                return MatchKind.Incomplete;
            }
        }
开发者ID:siatwangmin,项目名称:WinRTXamlToolkit,代码行数:61,代码来源:KeyGestureRecognizer.cs


注:本文中的VirtualKey.IsModifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。