Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何映射键盘_C#_.net - Fatal编程技术网

C# 如何映射键盘

C# 如何映射键盘,c#,.net,C#,.net,我正在映射键盘,但它无法处理某些字符或键,如f、g、[,]、;、''、\/那么,可能的解决方案是什么,以便我编码映射整个键盘。这是我尝试的代码,它在某些键上工作,但在某些键上不工作 private void richTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode.ToString().Equals(";")) { e.SuppressKeyPress = true; richText

我正在映射键盘,但它无法处理某些字符或键,如f、g、[,]、;、''、\/那么,可能的解决方案是什么,以便我编码映射整个键盘。这是我尝试的代码,它在某些键上工作,但在某些键上不工作

private void richTextBox_KeyDown(object sender, KeyEventArgs e)
{
   if (e.KeyCode.ToString().Equals(";"))
   {
      e.SuppressKeyPress = true;
      richTextBox.AppendText("Ū");
   }
   else if (e.KeyCode.ToString().Equals("/"))
   {
      e.SuppressKeyPress = true;
      richTextBox.AppendText("X̄");
   }
   else if (e.KeyCode.ToString().Equals("g"))
   {
      e.SuppressKeyPress = true;
      richTextBox.AppendText("Ʒ");
   }
}

您是否可以尝试这种方法,使用正确的键枚举和e.SuppressKeyPress

private void richTextBox_KeyDown(object sender, KeyEventArgs e)
 {
            // Handle special keys (Alt)
            if (e.Alt)
            {
                switch (e.KeyCode)
                {
                    case Keys.K:
                        richTextBox.AppendText("Alt+K pressed");
                e.SuppressKeyPress = true;
                        break;
                    default:
                        // Don't need to handle this
                        break;
                }
            }
            // Ctrl + key
            else if (e.Control)
            {


            }
            else
            { 
        switch (e.KeyCode)
        {
            case Keys.OemSemicolon:
                richTextBox.AppendText("Ū");
                e.SuppressKeyPress = true;
                break;
            case Keys.OemBackslash:
                richTextBox.AppendText("X̄");
                e.SuppressKeyPress = true;
                break;
            case Keys.G:
                richTextBox.AppendText("Ʒ");
                e.SuppressKeyPress = true;
                break;
            default:
                // Nothing special here
                break;
        }
    }
}

非常感谢,它可以工作,但是添加了这行代码。e、 SuppressKeyPress=true@SayyarHassan谢谢你,你能帮我标记一下吗?我会将您的编辑添加到我的答案中。您能告诉我,如果我想一次按两个或三个键执行一个操作,怎么办?因为字符多于键盘键。@SayyarHassan您的意思是Ctrl+K或Alt+Enter吗?非常感谢Jon,它可以工作。谢谢你抽出时间。