当在我的自定义 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/