How to convert a character to key code?

前端 未结 4 817
名媛妹妹
名媛妹妹 2020-12-11 01:35

How can I convert backslash key (\'\\\') to key code?

On my keyboard backslash code is 220, but the method below

(int)\'\\\\\'

ret

4条回答
  •  死守一世寂寞
    2020-12-11 02:12

    If

    var char = System.Windows.Forms.Keys.OemPipe; // 220
    var code = (int)char;
    

    then

    public static int ToKeyValue(this char ch)
    {
        return (int)(System.Windows.Forms.Keys)ch;
    }
    

提交回复
热议问题