Version: 5.3 (switch to 5.4b)
언어English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Input.GetKeyDown

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

닫기

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

닫기

취소

Switch to Manual
public static function GetKeyDown(name: string): bool;
public static bool GetKeyDown(string name);

파라미터

Description

유저가 /name/으로 식별된 키를 눌러 시작한 프레임 동안 true를 반환합니다.

You need to call this function from the Update function, since the state gets reset each frame. 유저가 키를 떼었다가 다시 누를때까지 true를 반환하지 않을 것 입니다.

For the list of key identifiers see Input Manager. When dealing with input it is recommended to use Input.GetAxis and Input.GetButton instead since it allows end-users to configure the keys.

	function Update () {
		if (Input.GetKeyDown ("space"))
			print ("space key was pressed");
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { if (Input.GetKeyDown("space")) print("space key was pressed"); } }

public static function GetKeyDown(key: KeyCode): bool;
public static bool GetKeyDown(KeyCode key);

파라미터

Description

Returns true during the frame the user starts pressing down the key identified by the key KeyCode enum parameter.

	function Update () {
		if (Input.GetKeyDown (KeyCode.Space))
			print ("space key was pressed");
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.Space)) print("space key was pressed"); } }