Get unicode value of character

后端 未结 4 1127
轻奢々
轻奢々 2020-12-20 01:09

Is there any way to get the keycode of a char? For example

getKeycode(\'C\');

Is there anything like that?

Thanks

相关标签:
4条回答
  • 2020-12-20 01:31
    public static int KeyEvent.getExtendedKeyCodeForChar( int key );
    

    This will return an extended key code for the unicode character key.

    As stated at here:

    Returns: for a unicode character with a corresponding VK_ constant -- this VK_ constant; for a character appearing on the primary level of a known keyboard layout -- a unique integer. If a character does not appear on the primary level of a known keyboard, VK_UNDEFINED is returned.

    0 讨论(0)
  • 2020-12-20 01:39
    char ch='c';
    int code = ch;
    System.out.println(code);
    

    OUTPUT:

    99
    

    just for escape char \ you have to use like char ch='\\';

    0 讨论(0)
  • 2020-12-20 01:42

    System.out.println((int) 'c');

    0 讨论(0)
  • 2020-12-20 01:46

    A way is this:

    char c = 'f';

    System.out.println("code="+(int)c);

    I mean, you should make a casting form char to int;

    0 讨论(0)
提交回复
热议问题