在Xamarin.Android中将Keycode转换为char

时间:2016-02-11 10:23:04

标签: xamarin xamarin.android keycode

在我的自定义视图中按下某个键时,会调用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" -> "\n"
"A"     -> "A"

2 个答案:

答案 0 :(得分:2)

尝试这样的事情:

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);
}

答案 1 :(得分:1)

根据Vaikesh的回答,这是解决方案:

<div class="csslider1 autoplay cs_handle" style="width:200px;">
        <input name="cs_anchor1" id="cs_slide1_0" type="radio" class="cs_anchor slide">
        <input name="cs_anchor1" id="cs_slide1_1" type="radio" class="cs_anchor slide">
        <input name="cs_anchor1" id="cs_slide1_2" type="radio" class="cs_anchor slide">
        <input name="cs_anchor1" id="cs_play1" type="radio" class="cs_anchor" checked="">
        <input name="cs_anchor1" id="cs_pause1_0" type="radio" class="cs_anchor pause">
        <input name="cs_anchor1" id="cs_pause1_1" type="radio" class="cs_anchor pause">
        <input name="cs_anchor1" id="cs_pause1_2" type="radio" class="cs_anchor pause">

        <ul>
            <div>
                <img src="https://s3.amazonaws.com/www.betaoutcdn.com/210522016/02/1455163105.png" style="width: 100%;">
            </div>
            <li class="num0 img">
                <a href="http://betaout.com" target="_blank">
                    <img src="https://s3.amazonaws.com/www.betaoutcdn.com/210522016/02/1455163105.png" alt="" title="">
                </a>
            </li>
            <li class="num1 img">
                <a href="http://betaout.com" target="_blank">
                    <img src="https://s3.amazonaws.com/www.betaoutcdn.com/210522016/02/1455163167.png" alt="" title="">
                </a>
            </li>
            <li class="num2 img">
                <a href="http://betaout.com" target="_blank">
                    <img src="https://s3.amazonaws.com/www.betaoutcdn.com/210522016/02/1455163189.png" alt="" title="">
                </a>
            </li>
        </ul>

	<div class="cs_play_pause">
		<label class="cs_play" for="cs_play1">Play</label>	
	</div>
	
        <div class="cs_arrowprev">
                <label class="num0" for="cs_slide1_0"><span><i></i></span></label>
                <label class="num1" for="cs_slide1_1"><span><i></i></span></label>
                <label class="num2" for="cs_slide1_2"><span><i></i></span></label>
        </div>
        <div class="cs_arrownext">
                <label class="num0" for="cs_slide1_0"><span><i></i></span></label>
                <label class="num1" for="cs_slide1_1"><span><i></i></span></label>
                <label class="num2" for="cs_slide1_2"><span><i></i></span></label>
        </div>

        <div class="cs_bullets">
                <label class="num0" for="cs_slide1_0">
                    <span class="cs_point"></span>
                </label>
                <label class="num1" for="cs_slide1_1">
                    <span class="cs_point"></span>
                </label>
                <label class="num2" for="cs_slide1_2">
                    <span class="cs_point"></span>
                </label>
        </div>
    </div>