【Unity3D—C#】按下任意按鍵,返回按鍵的名稱 以及 KeyCode鍵碼詳解

在OnGUI() 函數內使用事件Event方法,可返回按鍵KeyCode。按一次鍵會顯示兩次相同值。

void OnGUI()
        {
            Event e = Event.current;
            if (e.isKey)
                Debug.Log("Detected key code: " + e.keyCode);

        }

以下內容是KeyCode鍵碼。

KeyCode是由Event.keyCode返回的。這些直接映射到鍵盤上的物理鍵。

Values

  • Not assigned (never is pressed)
    未分配(永不被按下)。
  • The backspace key //退格鍵。
  • The forward delete key //正向刪除鍵。
  • The tab key //製表鍵。
  • The Clear key //清除鍵。
  • Return key //回車鍵。
  • Pause on PC machines //PC上的暫停鍵。
  • Escape key //退出鍵。
  • Space key //空格鍵。
  • Numeric keypad 0 //數字小鍵盤0。
  • Numeric keypad 1 //數字小鍵盤1。
  • Numeric keypad 2 //數字小鍵盤2。
  • Numeric keypad 3 //數字小鍵盤3。
  • Numeric keypad 4 //數字小鍵盤4。
  • Numeric keypad 5 //數字小鍵盤5。
  • Numeric keypad 6 //數字小鍵盤6。
  • Numeric keypad 7 //數字小鍵盤7。
  • Numeric keypad 8 //數字小鍵盤8。
  • Numeric keypad 9 //數字小鍵盤9。
  • Numeric keypad '.' // 數字小鍵盤的句點'.'。
  • Numeric keypad '/' // 數字小鍵盤的除號'/'。
  • Numeric keypad '*' //數字小鍵盤的乘號 '*'。
  • Numeric keypad '-' //數字小鍵盤的減號 '-'。
  • Numeric keypad '+' //數字小鍵盤的加號 '+'。
  • Numeric keypad enter //數字小鍵盤的回車鍵。
  • Numeric keypad '=' //數字小鍵盤的等號鍵'='。
  • Up arrow key //上箭頭鍵。
  • Down arrow key //下箭頭鍵。
  • Right arrow key //右箭頭鍵。
  • Left arrow key //左箭頭鍵。
  • Insert key key //插入鍵。
  • Home key //起始鍵。
  • End key //結束鍵。
  • Page up //上頁。
  • Page down //下頁。
  • F1 function key //F1功能鍵。
  • F2 function key //F2功能鍵。
  • F3 function key //F3功能鍵。
  • F4 function key //F4功能鍵。
  • F5 function key //F5功能鍵。
  • F6 function key //F6功能鍵。
  • F7 function key //F7功能鍵。
  • F8 function key //F8功能鍵。
  • F9 function key //F9功能鍵。
  • F10 function key //F10功能鍵。
  • F11 function key //F11功能鍵。
  • F12 function key //F12功能鍵。
  • F13 function key //F13功能鍵。
  • F14 function key //F14功能鍵。
  • F15 function key //F15功能鍵。
  • The '0' key on the top of the alphanumeric keyboard.
    鍵盤頂部的數字鍵'0'。
  • The '1' key on the top of the alphanumeric keyboard.
    鍵盤頂部的數字鍵'1'。
  • The '2' key on the top of the alphanumeric keyboard.
    鍵盤頂部的數字鍵'2'。
  • The '3' key on the top of the alphanumeric keyboard.
    鍵盤頂部的數字鍵'3'。
  • The '4' key on the top of the alphanumeric keyboard.
    鍵盤頂部的數字鍵'4'。
  • The '5' key on the top of the alphanumeric keyboard.
    鍵盤頂部的數字鍵'5'。
  • The '6' key on the top of the alphanumeric keyboard.
    鍵盤頂部的數字鍵'6'。
  • The '7' key on the top of the alphanumeric keyboard.
    鍵盤頂部的數字鍵'7'。
  • The '8' key on the top of the alphanumeric keyboard.
    鍵盤頂部的數字鍵'8'。
  • The '9' key on the top of the alphanumeric keyboard.
    鍵盤頂部的數字鍵'9'。
  • Explaim key //感嘆號鍵'!'。
  • Double quote key //雙引號鍵。
  • Hash key //哈希鍵。
  • Dollar sign key //美元符號鍵。
  • Ampersand key //和,  &(and 的符號)鍵。
  • Quote key //單引號鍵。
  • Left Parent key //左括號鍵。
  • Right Parent key //右括號鍵。
  • Asterisk key //星號鍵 * 。
  • Plus key //加號鍵 + 。
  • Comma ',' key //逗號鍵 , 。
  • Minus '-' key //減號鍵 - 。
  • Period '.' key //句號鍵 . 。
  • Slash '/' key //斜槓鍵 / 。
  • Colon ':' key //冒號鍵 : 。
  • Semicolon ';' key //分號鍵 ; 。
  • Less '<' key //小於號鍵 < 。
  • Equals '=' key //等於號鍵 = 。
  • Greater '>' key //大於號鍵 > 。
  • Question mark '?' key //問號鍵 ? 。
  • At key //@符號鍵。
  • Left bracket key //左方括號鍵 [ 。
  • Backslash key //反斜槓鍵 \ 。
  • Right bracket key //右方括號鍵 ] 。
  • Caret key //脫字符鍵 ^ 。
  • Underscore '_' key //下劃線鍵 _ 。
  • Back quote key //反引號鍵 。
  • 'a' key // a鍵
  • 'b' key // b鍵
  • 'c' key // c鍵
  • 'd' key // d鍵
  • 'e' key // e鍵
  • 'f' key // f鍵
  • 'g' key // g鍵
  • 'h' key // h鍵
  • 'i' key // i鍵
  • 'j' key // j鍵
  • 'k' key // k鍵
  • 'l' key // l鍵
  • 'm' key // m鍵
  • 'n' key // n鍵
  • 'o' key // o鍵
  • 'p' key // p鍵
  • 'q' key // q鍵
  • 'r' key // r鍵
  • 's' key // s鍵
  • 't' key // t鍵
  • 'u' key // u鍵
  • 'v' key // v鍵
  • 'w' key // w鍵
  • 'x' key // x鍵
  • 'y' key // y鍵
  • 'z' key // z鍵
  • Numlock key //數字鎖定鍵 。
  • Capslock key //大寫鎖定鍵 。
  • Scroll lock key //滾動鎖定鍵 。
  • Right shift key //右上檔鍵。
  • Left shift key //左上檔鍵。
  • Right Control key //右控制鍵。
  • Left Control key //左控制鍵。
  • Right Alt key //右更改鍵。
  • Left Alt key //左更改鍵。
  • Left Apple key //左蘋果鍵。
  • Left Windows key //左Windows鍵。
  • Right Apple key //右蘋果鍵。
  • Right Windows key //右Windows鍵。
  • Alt Gr key //右側更改鍵。
  • Help key //幫助鍵。
  • Print key //打印鍵。
  • Sys Req key //系統請求鍵。
  • Break key //中斷鍵。
  • Menu key //菜單鍵。
  • First (primary) mouse button 
    第一個(主)鼠標鍵(鼠標左鍵)。
  • Second (secondary) mouse button
    第二個(次)鼠標鍵(鼠標右鍵)。
  • Third mouse button //第三個鼠標鍵(鼠標中鍵)。
  • Fourth mouse button //第四個鼠標鍵
  • Fifth mouse button //第五個鼠標鍵。
  • Sixth mouse button //第六個鼠標鍵。
  • Seventh mouse button //第七個鼠標鍵。
  • Button 0 on any joystick //手柄按鍵0。
  • Button 1 on any joystick //手柄按鍵1。
  • Button 2 on any joystick //手柄按鍵2。
  • Button 3 on any joystick //手柄按鍵3。
  • Button 4 on any joystick //手柄按鍵4。
  • Button 5 on any joystick //手柄按鍵5。
  • Button 6 on any joystick //手柄按鍵6。
  • Button 7 on any joystick //手柄按鍵7。
  • Button 8 on any joystick //手柄按鍵8。
  • Button 9 on any joystick //手柄按鍵9。
  • Button 10 on any joystick //手柄按鍵10。
  • Button 11 on any joystick //手柄按鍵11。
  • Button 12 on any joystick //手柄按鍵12。
  • Button 13 on any joystick //手柄按鍵13。
  • Button 14 on any joystick //手柄按鍵14。
  • Button 15 on any joystick //手柄按鍵15。
  • Button 16 on any joystick //手柄按鍵16。
  • Button 17 on any joystick //手柄按鍵17。
  • Button 18 on any joystick //手柄按鍵18。
  • Button 19 on any joystick //手柄按鍵19。
  • Button 0 on first joystick //第一個手柄按鍵0。
  • Button 1 on first joystick //第一個手柄按鍵1。
  • Button 2 on first joystick //第一個手柄按鍵2。
  • Button 3 on first joystick //第一個手柄按鍵3。
  • Button 4 on first joystick //第一個手柄按鍵4。
  • Button 5 on first joystick //第一個手柄按鍵5。
  • Button 6 on first joystick //第一個手柄按鍵6。
  • Button 7 on first joystick //第一個手柄按鍵7。
  • Button 8 on first joystick //第一個手柄按鍵8。
  • Button 9 on first joystick //第一個手柄按鍵9。
  • Button 10 on first joystick //第一個手柄按鍵10。
  • Button 11 on first joystick //第一個手柄按鍵11。
  • Button 12 on first joystick //第一個手柄按鍵12。
  • Button 13 on first joystick //第一個手柄按鍵13。
  • Button 14 on first joystick //第一個手柄按鍵14。
  • Button 15 on first joystick //第一個手柄按鍵15。
  • Button 16 on first joystick //第一個手柄按鍵16。
  • Button 17 on first joystick //第一個手柄按鍵17。
  • Button 18 on first joystick //第一個手柄按鍵18。
  • Button 19 on first joystick //第一個手柄按鍵19。
  • Button 0 on second joystick //第二個手柄按鍵0。
  • Button 1 on second joystick //第二個手柄按鍵1。
  • Button 2 on second joystick //第二個手柄按鍵2。
  • Button 3 on second joystick //第二個手柄按鍵3。
  • Button 4 on second joystick //第二個手柄按鍵4。
  • Button 5 on second joystick //第二個手柄按鍵5。
  • Button 6 on second joystick //第二個手柄按鍵6。
  • Button 7 on second joystick //第二個手柄按鍵7。
  • Button 8 on second joystick //第二個手柄按鍵8。
  • Button 9 on second joystick //第二個手柄按鍵9。
  • Button 10 on second joystick //第二個手柄按鍵10。
  • Button 11 on second joystick //第二個手柄按鍵11。
  • Button 12 on second joystick //第二個手柄按鍵12。
  • Button 13 on second joystick //第二個手柄按鍵13。
  • Button 14 on second joystick //第二個手柄按鍵14。
  • Button 15 on second joystick //第二個手柄按鍵15。
  • Button 16 on second joystick //第二個手柄按鍵16。
  • Button 17 on second joystick //第二個手柄按鍵17。
  • Button 18 on second joystick //第二個手柄按鍵18。
  • Button 19 on second joystick //第二個手柄按鍵19。
  • Button 0 on third joystick //第三個手柄按鍵0。
  • Button 1 on third joystick //第三個手柄按鍵1。
  • Button 2 on third joystick //第三個手柄按鍵2。
  • Button 3 on third joystick //第三個手柄按鍵3。
  • Button 4 on third joystick //第三個手柄按鍵4。
  • Button 5 on third joystick //第三個手柄按鍵5。
  • Button 6 on third joystick //第三個手柄按鍵6。
  • Button 7 on third joystick //第三個手柄按鍵7。
  • Button 8 on third joystick //第三個手柄按鍵8。
  • Button 9 on third joystick //第三個手柄按鍵9。
  • Button 10 on third joystick //第三個手柄按鍵10。
  • Button 11 on third joystick //第三個手柄按鍵11。
  • Button 12 on third joystick //第三個手柄按鍵12。
  • Button 13 on third joystick //第三個手柄按鍵13。
  • Button 14 on third joystick //第三個手柄按鍵14。
  • Button 15 on third joystick //第三個手柄按鍵15。
  • Button 16 on third joystick //第三個手柄按鍵16。
  • Button 17 on third joystick //第三個手柄按鍵17。
  • Button 18 on third joystick //第三個手柄按鍵18。
  • Button 19 on third joystick //第三個手柄按鍵19。

此博客僅用於知識學習及分享!

源自:https://blog.csdn.net/poem_of_sunshine/article/details/39699285

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章