Version: 2022.2
言語: 日本語

KeyCode

enumeration

マニュアルに切り替える

説明

Key codes returned by Event.keyCode. These map directly to a physical key on the keyboard. If "Use Physical Keys" is enabled in Input Manager settings, these map directly to a physical key on the keyboard. If "Use Physical Keys" is disabled these map to language dependent mapping, different for every platform and cannot be guaranteed to work. "Use Physical Keys" is enabled by default from 2022.1

Key codes can be used to detect key down and key up events, using Input.GetKeyDown and Input.GetKeyUp:

using UnityEngine;

public class KeyCodeExample : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("Space key was pressed."); }

if (Input.GetKeyUp(KeyCode.Space)) { Debug.Log("Space key was released."); } } }

Keyboard events can also be captured within OnGUI:

using UnityEngine;

public class KeyCodeOnGUIExample : MonoBehaviour { void OnGUI() { if (Event.current.Equals(Event.KeyboardEvent(KeyCode.Space.ToString()))) { Debug.Log("Space key is pressed."); } } }

For joystick and gamepad button presses, consider using Input.GetButtonDown and Input.GetButtonUp instead of the KeyCode. These methods allow you to check input state using a descriptive action string, e.g. "fire" or "jump", instead of the hardware button number.

The Input pages provide details about accessing keyboard, mouse and joystick input.

変数

None割り当てなし(キーストロークの結果として戻り値となることはありません)
Backspacebackspace
DeleteDelete
TabTab
ClearClear
ReturnReturn
PausePause
EscapeEscape
SpaceSpace
Keypad0テンキー 0
Keypad1テンキー 1
Keypad2テンキー 2
Keypad3テンキー 3
Keypad4テンキー 4
Keypad5テンキー 5
Keypad6テンキー 6
Keypad7テンキー 7
Keypad8テンキー 8
Keypad9テンキー 9
KeypadPeriodテンキーの .
KeypadDivideテンキーの/
KeypadMultiplyテンキーの*
KeypadMinusテンキーの-
KeypadPlusテンキーの+
KeypadEnterNumeric keypad Enter.
KeypadEqualsテンキーの=
UpArrow上矢印キー
DownArrow下矢印キー
RightArrow右矢印キー
LeftArrow左矢印キー
InsertInsert
HomeHome
EndEnd
PageUpPage up
PageDownPage down
F1F1
F2F2
F3F3
F4F4
F5F5
F6F6
F7F7
F8F8
F9F9
F10F10
F11F11
F12F12
F13F13
F14F14
F15F15
Alpha0キーボード上の 0
Alpha1キーボード上の 1
Alpha2キーボード上の 2
Alpha3キーボード上の 3
Alpha4キーボード上の 4
Alpha5キーボード上の 5
Alpha6キーボード上の 6
Alpha7キーボード上の 7
Alpha8キーボード上の 8
Alpha9キーボード上の 9
ExclaimExclamation mark key '!'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Alpha1 instead.
DoubleQuoteDouble quote key '"'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Quote instead.
HashHash key '#'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Alpha3 instead.
DollarDollar sign key '$'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Alpha4 instead.
PercentPercent '%' key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Alpha5 instead.
AmpersandAmpersand key '&'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Alpha7 instead.
Quote'
LeftParenLeft Parenthesis key '('. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Alpha9 instead.
RightParenRight Parenthesis key ')'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Alpha0 instead.
AsteriskAsterisk key '*'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Alpha8 instead.
PlusPlus key '+'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Equals instead.
Comma
Minus-
Period.
Slash/
ColonColon ':' key.Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Semicolon instead.
Semicolon;
LessLess than '<' key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Comma instead.
Equals=
GreaterGreater than '>' key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Period instead.
QuestionQuestion mark '?' key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Slash instead.
AtAt key '@'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Alpha2 instead.
LeftBracket[
Backslash
RightBracket]
CaretCaret key '^'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Alpha6 instead.
UnderscoreUnderscore '_' key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Minus instead.
BackQuote`
Aa
Bb
Cc
Dd
Ee
Ff
Gg
Hh
Ii
Jj
Kk
Ll
Mm
Nn
Oo
Pp
Qq
Rr
Ss
Tt
Uu
Vv
Ww
Xx
Yy
Zz
LeftCurlyBracketLeft curly bracket key '{'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.LeftBracket instead.
PipePipe '|' key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.Backslash instead.
RightCurlyBracketRight curly bracket key '}'. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.RightBracket instead.
TildeTilde '~' key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.BackQuote instead.
NumlockNumlock
CapsLockCapslock
ScrollLockScroll Lock
RightShiftRight Shift
LeftShiftLeft Shift
RightControlRight Control
LeftControlLeft Control
RightAltRight Alt
LeftAltLeft Alt
LeftMetaMaps to left Windows key or left Command key if physical keys are enabled in Input Manager settings, otherwise maps to left Command key only.
LeftCommandLeft Command
LeftAppleLeft Command
LeftWindowsLeft Windows key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.LeftMeta instead.
RightMetaMaps to right Windows key or right Command key if physical keys are enabled in Input Manager settings, otherwise maps to right Command key only.
RightCommandRight Command
RightAppleRight Command
RightWindowsRight Windows key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.RightMeta instead.
AltGrAlt Gr key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, use KeyCode.RightAlt instead.
HelpHelp key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, doesn't map to any physical key.
PrintPrint
SysReqSys Req key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, doesn't map to any physical key.
BreakBreak key. Deprecated if "Use Physical Keys" is enabled in Input Manager settings, doesn't map to any physical key.
MenuMenu
Mouse0The Left (or primary) mouse button.
Mouse1Right mouse button (or secondary mouse button).
Mouse2Middle mouse button (or third button).
Mouse3Additional (fourth) mouse button.
Mouse4Additional (fifth) mouse button.
Mouse5Additional (or sixth) mouse button.
Mouse6Additional (or seventh) mouse button.
JoystickButton0ジョイスティックの 0 ボタン
JoystickButton1ジョイスティックの 1 ボタン
JoystickButton2ジョイスティックの 2 ボタン
JoystickButton3ジョイスティックの 3 ボタン
JoystickButton4ジョイスティックの 4 ボタン
JoystickButton5ジョイスティックの 5 ボタン
JoystickButton6ジョイスティックの 6 ボタン
JoystickButton7ジョイスティックの 7 ボタン
JoystickButton8ジョイスティックの 8 ボタン
JoystickButton9ジョイスティックの 9 ボタン
JoystickButton10ジョイスティックの 10 ボタン
JoystickButton11ジョイスティックの 11 ボタン
JoystickButton12ジョイスティックの 12 ボタン
JoystickButton13ジョイスティックの 13 ボタン
JoystickButton14ジョイスティックの 14 ボタン
JoystickButton15ジョイスティックの 15 ボタン
JoystickButton16ジョイスティックの 16 ボタン
JoystickButton17ジョイスティックの 17 ボタン
JoystickButton18ジョイスティックの 18 ボタン
JoystickButton19ジョイスティックの 19 ボタン
Joystick1Button0ジョイスティック 1 の 0 ボタン
Joystick1Button1ジョイスティック 1 の 1 ボタン
Joystick1Button2ジョイスティック 1 の 2 ボタン
Joystick1Button3ジョイスティック 1 の 3 ボタン
Joystick1Button4ジョイスティック 1 の 4 ボタン
Joystick1Button5ジョイスティック 1 の 5 ボタン
Joystick1Button6ジョイスティック 1 の 6 ボタン
Joystick1Button7ジョイスティック 1 の 7 ボタン
Joystick1Button8ジョイスティック 1 の 8 ボタン
Joystick1Button9ジョイスティック 1 の 9 ボタン
Joystick1Button10ジョイスティック 1 の 10 ボタン
Joystick1Button11ジョイスティック 1 の 11 ボタン
Joystick1Button12ジョイスティック 1 の 12 ボタン
Joystick1Button13ジョイスティック 1 の 13 ボタン
Joystick1Button14ジョイスティック 1 の 14 ボタン
Joystick1Button15ジョイスティック 1 の 15 ボタン
Joystick1Button16ジョイスティック 1 の 16 ボタン
Joystick1Button17ジョイスティック 1 の 17 ボタン
Joystick1Button18ジョイスティック 1 の 18 ボタン
Joystick1Button19ジョイスティック 1 の 19 ボタン
Joystick2Button0ジョイスティック 2 の 0 ボタン
Joystick2Button1ジョイスティック 2 の 1 ボタン
Joystick2Button2ジョイスティック 2 の 2 ボタン
Joystick2Button3ジョイスティック 2 の 3 ボタン
Joystick2Button4ジョイスティック 2 の 4 ボタン
Joystick2Button5ジョイスティック 2 の 5 ボタン
Joystick2Button6ジョイスティック 2 の 6 ボタン
Joystick2Button7ジョイスティック 2 の 7 ボタン
Joystick2Button8ジョイスティック 2 の 8 ボタン
Joystick2Button9ジョイスティック 2 の 9 ボタン
Joystick2Button10ジョイスティック 2 の 10 ボタン
Joystick2Button11ジョイスティック 2 の 11 ボタン
Joystick2Button12ジョイスティック 2 の 12 ボタン
Joystick2Button13ジョイスティック 2 の 13 ボタン
Joystick2Button14ジョイスティック 2 の 14 ボタン
Joystick2Button15ジョイスティック 2 の 15 ボタン
Joystick2Button16ジョイスティック 2 の 16 ボタン
Joystick2Button17ジョイスティック 2 の 17 ボタン
Joystick2Button18ジョイスティック 2 の 18 ボタン
Joystick2Button19ジョイスティック 2 の 19 ボタン
Joystick3Button0ジョイスティック 3 の 0 ボタン
Joystick3Button1ジョイスティック 3 の 1 ボタン
Joystick3Button2ジョイスティック 3 の 2 ボタン
Joystick3Button3ジョイスティック 3 の 3 ボタン
Joystick3Button4ジョイスティック 3 の 4 ボタン
Joystick3Button5ジョイスティック 3 の 5 ボタン
Joystick3Button6ジョイスティック 3 の 6 ボタン
Joystick3Button7ジョイスティック 3 の 7 ボタン
Joystick3Button8ジョイスティック 3 の 8 ボタン
Joystick3Button9ジョイスティック 3 の 9 ボタン
Joystick3Button10ジョイスティック 3 の 10 ボタン
Joystick3Button11ジョイスティック 3 の 11 ボタン
Joystick3Button12ジョイスティック 3 の 12 ボタン
Joystick3Button13ジョイスティック 3 の 13 ボタン
Joystick3Button14ジョイスティック 3 の 14 ボタン
Joystick3Button15ジョイスティック 3 の 15 ボタン
Joystick3Button16ジョイスティック 3 の 16 ボタン
Joystick3Button17ジョイスティック 3 の 17 ボタン
Joystick3Button18ジョイスティック 3 の 18 ボタン
Joystick3Button19ジョイスティック 3 の 19 ボタン
Joystick4Button0ジョイスティック 4 の 0 ボタン
Joystick4Button1ジョイスティック 4 の 1 ボタン
Joystick4Button2ジョイスティック 4 の 2 ボタン
Joystick4Button3ジョイスティック 4 の 3 ボタン
Joystick4Button4ジョイスティック 4 の 4 ボタン
Joystick4Button5ジョイスティック 4 の 5 ボタン
Joystick4Button6ジョイスティック 4 の 6 ボタン
Joystick4Button7ジョイスティック 4 の 7 ボタン
Joystick4Button8ジョイスティック 4 の 8 ボタン
Joystick4Button9ジョイスティック 4 の 9 ボタン
Joystick4Button10ジョイスティック 4 の 10 ボタン
Joystick4Button11ジョイスティック 4 の 11 ボタン
Joystick4Button12ジョイスティック 4 の 12 ボタン
Joystick4Button13ジョイスティック 4 の 13 ボタン
Joystick4Button14ジョイスティック 4 の 14 ボタン
Joystick4Button15ジョイスティック 4 の 15 ボタン
Joystick4Button16ジョイスティック 4 の 16 ボタン
Joystick4Button17ジョイスティック 4 の 17 ボタン
Joystick4Button18ジョイスティック 4 の 18 ボタン
Joystick4Button19ジョイスティック 4 の 19 ボタン
Joystick5Button0ジョイスティック 5 の 0 ボタン
Joystick5Button1ジョイスティック 4 の 1 ボタン
Joystick5Button2ジョイスティック 4 の 2 ボタン
Joystick5Button3ジョイスティック 4 の 3 ボタン
Joystick5Button4ジョイスティック 4 の 4 ボタン
Joystick5Button5ジョイスティック 4 の 5 ボタン
Joystick5Button6ジョイスティック 5 の 6 ボタン
Joystick5Button7ジョイスティック 5 の 7 ボタン
Joystick5Button8ジョイスティック 5 の 8 ボタン
Joystick5Button9ジョイスティック 5 の 9 ボタン
Joystick5Button10ジョイスティック 5 の 10 ボタン
Joystick5Button11ジョイスティック 5 の 11 ボタン
Joystick5Button12ジョイスティック 5 の 12 ボタン
Joystick5Button13ジョイスティック 5 の 13 ボタン
Joystick5Button14ジョイスティック 5 の 14 ボタン
Joystick5Button15ジョイスティック 5 の 15 ボタン
Joystick5Button16ジョイスティック 5 の 16 ボタン
Joystick5Button17ジョイスティック 5 の 17 ボタン
Joystick5Button18ジョイスティック 5 の 18 ボタン
Joystick5Button19ジョイスティック 5 の 19 ボタン
Joystick6Button0ジョイスティック 6 の 0 ボタン
Joystick6Button1ジョイスティック 6 の 1 ボタン
Joystick6Button2ジョイスティック 6 の 2 ボタン
Joystick6Button3ジョイスティック 6 の 3 ボタン
Joystick6Button4ジョイスティック 6 の 4 ボタン
Joystick6Button5ジョイスティック 6 の 5 ボタン
Joystick6Button6ジョイスティック 6 の 6 ボタン
Joystick6Button7ジョイスティック 6 の 7 ボタン
Joystick6Button8ジョイスティック 6 の 8 ボタン
Joystick6Button9ジョイスティック 6 の 9 ボタン
Joystick6Button10ジョイスティック 6 の 10 ボタン
Joystick6Button11ジョイスティック 6 の 11 ボタン
Joystick6Button12ジョイスティック 6 の 12 ボタン
Joystick6Button13ジョイスティック 6 の 13 ボタン
Joystick6Button14ジョイスティック 6 の 14 ボタン
Joystick6Button15ジョイスティック 6 の 15 ボタン
Joystick6Button16ジョイスティック 6 の 16 ボタン
Joystick6Button17ジョイスティック 6 の 17 ボタン
Joystick6Button18ジョイスティック 6 の 18 ボタン
Joystick6Button19ジョイスティック 6 の 19 ボタン
Joystick7Button0ジョイスティック 7 の 0 ボタン
Joystick7Button1ジョイスティック 7 の 1 ボタン
Joystick7Button2ジョイスティック 7 の 2 ボタン
Joystick7Button3ジョイスティック 7 の 3 ボタン
Joystick7Button4ジョイスティック 7 の 4 ボタン
Joystick7Button5ジョイスティック 7 の 5 ボタン
Joystick7Button6ジョイスティック 7 の 6 ボタン
Joystick7Button7ジョイスティック 7 の 7 ボタン
Joystick7Button8ジョイスティック 7 の 8 ボタン
Joystick7Button9ジョイスティック 7 の 9 ボタン
Joystick7Button10ジョイスティック 7 の 10 ボタン
Joystick7Button11ジョイスティック 7 の 11 ボタン
Joystick7Button12ジョイスティック 7 の 12 ボタン
Joystick7Button13ジョイスティック 7 の 13 ボタン
Joystick7Button14ジョイスティック 7 の 14 ボタン
Joystick7Button15ジョイスティック 7 の 15 ボタン
Joystick7Button16ジョイスティック 7 の 16 ボタン
Joystick7Button17ジョイスティック 7 の 17 ボタン
Joystick7Button18ジョイスティック 7 の 18 ボタン
Joystick7Button19ジョイスティック 7 の 19 ボタン
Joystick8Button0ジョイスティック 8 の 0 ボタン
Joystick8Button1ジョイスティック 8 の 1 ボタン
Joystick8Button2ジョイスティック 8 の 2 ボタン
Joystick8Button3ジョイスティック 8 の 3 ボタン
Joystick8Button4ジョイスティック 8 の 4 ボタン
Joystick8Button5ジョイスティック 8 の 5 ボタン
Joystick8Button6ジョイスティック 8 の 6 ボタン
Joystick8Button7ジョイスティック 8 の 7 ボタン
Joystick8Button8ジョイスティック 8 の 8 ボタン
Joystick8Button9ジョイスティック 8 の 9 ボタン
Joystick8Button10ジョイスティック 8 の 10 ボタン
Joystick8Button11ジョイスティック 8 の 11 ボタン
Joystick8Button12ジョイスティック 8 の 12 ボタン
Joystick8Button13ジョイスティック 8 の 13 ボタン
Joystick8Button14ジョイスティック 8 の 14 ボタン
Joystick8Button15ジョイスティック 8 の 15 ボタン
Joystick8Button16ジョイスティック 8 の 16 ボタン
Joystick8Button17ジョイスティック 8 の 17 ボタン
Joystick8Button18ジョイスティック 8 の 18 ボタン
Joystick8Button19ジョイスティック 8 の 19 ボタン