在Xamarin.Android中将Keycode转换为char

追风赶月莫停留,平芜尽处是春山。这篇文章主要讲述在Xamarin.Android中将Keycode转换为char相关的知识,希望能为你提供帮助。
【在Xamarin.Android中将Keycode转换为char】在我的自定义视图中按下某个键时,会调用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? }

如何将Keycode转换为char?例如:
"Space" -> " " "Enter" -> " " "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); }

另一答案根据Vaikesh的回答,这是解决方案:
private void OnKeyPress(object sender, KeyEventArgs e) { char c = Convert.ToChar(e.UnicodeChar); }


    推荐阅读