Reputation: 550
When a key is pressed in my custom View, OnKeyPress is called:
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?
}
How do i convert the Keycode to a char? For instance:
"Space" -> " "
"Enter" -> "\n"
"A" -> "A"
Upvotes: 2
Views: 1766
Reputation: 550
Based on Vaikesh's answer, this is the solution:
private void OnKeyPress(object sender, KeyEventArgs e)
{
char c = Convert.ToChar(e.UnicodeChar);
}
Upvotes: 2
Reputation: 3306
Try something like this :
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);
}
Upvotes: 2