xamarin - 在 Xamarin.Android 中将 Keycode 转换为 char

标签 xamarin xamarin.android keycode

当在我的自定义 View 中按下某个键时,将调用 OnKeyPress:

public DrawView(Context context, IAttributeSet attributeSet) : base(context, attributeSet)
{
        KeyPress += OnKeyPress;
}

private void OnKeyPress(object sender, KeyEventArgs e)
{
        Keycode code = e.KeyCode;
        // How to convert to char?
}

如何将 key 代码转换为字符?例如:

"Space" -> " "
"Enter" -> "\n"
"A"     -> "A"

最佳答案

尝试这样的事情:

public override bool OnKeyUp (Keycode keyCode, KeyEvent e)
{
    char keyPressed = (char) e.GetUnicodeChar();
    Log.Debug (string.Format ("On KeyUp is:{0}", keyPressed));
    return base.OnKeyUp (keyCode, e);
}

关于xamarin - 在 Xamarin.Android 中将 Keycode 转换为 char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35336602/

相关文章:

android - 将 ScrollView 定位在 RelativeLayout 内的 LinearLayout 下方

c# - 我们如何共享我们的 xamarin 应用程序?

java - 解析特殊键字符串以获得KeyCode

python - 如何在 Python 中获取键码

Javascript 键码冲突 : "right arrow" and "single quote"

android - 在包 (APT0000) Xamarin ConstraintLayout 中找不到属性 'layout_constraintTop_toBottomOf' 的资源标识符

android - Xamarin - Shell.Current.GoToAsync 和后退按钮

android - Xamarin Android 7+ 以编程方式安装 APK

ios - 目录 '/Users/vsts/agent/2.152.1/work/16/a' 为空。不会添加任何内容来构建工件 'drop'

C# 向 .net 枚举添加额外值