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


C# KeyModifiers.HasFlag方法代码示例

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


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

示例1: GetFunctionKeyModifier

        /// <summary>
        /// Gets an ANSI function key modifier string representing the pressed <see cref="KeyModifiers"/>.
        /// </summary>
        /// <param name="keyModifiers">The pressed key modifiers.</param>
        /// <returns>The ANSI function key modifier string.</returns>
        private static string GetFunctionKeyModifier(KeyModifiers keyModifiers)
        {
            // This method is disabled at the moment...
            return string.Empty;

            bool isShiftKeyDown = keyModifiers.HasFlag(KeyModifiers.Shift);
            bool isAltKeyDown = keyModifiers.HasFlag(KeyModifiers.Alt);
            bool isControlKeyDown = keyModifiers.HasFlag(KeyModifiers.Ctrl);

            if (isShiftKeyDown && !isAltKeyDown && !isControlKeyDown)
            {
                return ";2";
            }
            else if (!isShiftKeyDown && isAltKeyDown && !isControlKeyDown)
            {
                return ";3";
            }
            else if (isShiftKeyDown && isAltKeyDown && !isControlKeyDown)
            {
                return ";4";
            }
            else if (!isShiftKeyDown && !isAltKeyDown && isControlKeyDown)
            {
                return ";5";
            }
            else if (isShiftKeyDown && !isAltKeyDown && isControlKeyDown)
            {
                return ";6";
            }
            else if (!isShiftKeyDown && isAltKeyDown && isControlKeyDown)
            {
                return ";7";
            }
            else if (isShiftKeyDown && isAltKeyDown && isControlKeyDown)
            {
                return ";8";
            }

            return string.Empty;
        }
开发者ID:yiyi99,项目名称:RemoteTerminal,代码行数:45,代码来源:SshTerminal.cs

示例2: ProcessUserInput

        /// <summary>
        /// Processes user input in a way that is specific to the terminal implementation.
        /// </summary>
        /// <param name="key">The input key.</param>
        /// <param name="keyModifiers">The key modifiers.</param>
        /// <returns>A value indicating whether the key press was processed by the terminal implementation.</returns>
        /// <remarks>
        /// This method receives key presses of non-character keys (e.g. Up, Down, Left, Right, Function keys F1-F12, Alt/Ctrl key combinations, ...).
        /// </remarks>
        protected override bool ProcessUserInput(VirtualKey key, KeyModifiers keyModifiers)
        {
            string input;

            // handle Alt key combinations
            if (keyModifiers.HasFlag(KeyModifiers.Alt))
            {
                if (key >= VirtualKey.Number0 && key <= VirtualKey.Number9)
                {
                    input = "\x1b" + (char)key;
                }
                else if (key >= VirtualKey.A && key <= VirtualKey.Z)
                {
                    // the "+ 32" produces lower case characters
                    input = "\x1b" + (char)(key + (keyModifiers.HasFlag(KeyModifiers.Shift) ? 0 : 32));
                }
                else if (key == VirtualKey.Shift || key == VirtualKey.Menu || key == VirtualKey.Control)
                {
                    return false;
                }
                else
                {
                    return false;
                }
            }
            else if (keyModifiers == KeyModifiers.Ctrl)
            {
                if (key == VirtualKey.Space)
                {
                    this.ignoreStringUserInput = true;
                    input = "\0";
                }
                else if (key == VirtualKey.Shift || key == VirtualKey.Menu || key == VirtualKey.Control)
                {
                    return false;
                }
                else if (key == (VirtualKey)191) // Ctrl + / (US keyboard)
                {
                    input = "\x1f";
                }
                else
                {
                    return false;
                }
            }
            else
            {
                switch (key)
                {
                    case VirtualKey.Back:
                        this.ignoreStringUserInput = true;
                        input = "\x7f";
                        break;
                    case VirtualKey.Enter:
                        input = Environment.NewLine;
                        break;
                    case VirtualKey.Tab:
                        input = "\t";
                        break;
                    case VirtualKey.Left:
                        input = this.applicationCursorKeys ? "\u001bOD" : "\u001b[D";
                        break;
                    case VirtualKey.Up:
                        input = this.applicationCursorKeys ? "\u001bOA" : "\u001b[A";
                        break;
                    case VirtualKey.Right:
                        input = this.applicationCursorKeys ? "\u001bOC" : "\u001b[C";
                        break;
                    case VirtualKey.Down:
                        input = this.applicationCursorKeys ? "\u001bOB" : "\u001b[B";
                        break;
                    case VirtualKey.Insert:
                        input = "\u001b[2~";
                        break;
                    case VirtualKey.Delete:
                        input = "\u001b[3~";
                        break;
                    case VirtualKey.Home:
                        input = "\u001b[1~";
                        break;
                    case VirtualKey.End:
                        input = "\u001b[4~";
                        break;
                    case VirtualKey.PageUp:
                        input = "\u001b[5~";
                        break;
                    case VirtualKey.PageDown:
                        input = "\u001b[6~";
                        break;
                    case VirtualKey.F1:
                        input = "\u001b[11" + GetFunctionKeyModifier(keyModifiers) + "~";
//.........这里部分代码省略.........
开发者ID:yiyi99,项目名称:RemoteTerminal,代码行数:101,代码来源:SshTerminal.cs


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