# Class: Key

## Phaser. Key

If you need more fine-grained control over the handling of specific keys you can create and use Phaser.Key objects.

#### new Key(game, keycode)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `game` | Phaser.Game | Current game instance.
  `keycode` | number | The key code this Key is responsible for.

  Source:
    - input/Key.js, line 14

### Members

#### altKey

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `altKey` | boolean | The down state of the ALT key, if pressed at the same time as this key.

  Default Value:
    - false
  Source:
    - input/Key.js, line 49

#### ctrlKey

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `ctrlKey` | boolean | The down state of the CTRL key, if pressed at the same time as this key.

  Default Value:
    - false
  Source:
    - input/Key.js, line 55

#### duration

  If the key is down this value holds the duration of that key press and is constantly updated. If the key is up it holds the duration of the previous down session.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `duration` | number | The number of milliseconds this key has been held down for.

  Default Value:
    - 0
  Source:
    - input/Key.js, line 74

#### enabled

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `enabled` | boolean | An enabled key processes its update and dispatches events. You can toggle this at run-time to disable a key without deleting it.

  Default Value:
    - true
  Source:
    - input/Key.js, line 25

#### <readonly> event

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `event` | object | Stores the most recent DOM event.

  Source:
    - input/Key.js, line 31

#### game

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `game` | Phaser.Game | A reference to the currently running game.

  Source:
    - input/Key.js, line 19

#### isDown

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `isDown` | boolean | The "down" state of the key.

  Default Value:
    - false
  Source:
    - input/Key.js, line 37

#### isUp

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `isUp` | boolean | The "up" state of the key.

  Default Value:
    - true
  Source:
    - input/Key.js, line 43

#### keyCode

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `keyCode` | number | The keycode of this key.

  Source:
    - input/Key.js, line 91

#### onDown

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `onDown` | Phaser.Signal | This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again).

  Source:
    - input/Key.js, line 96

#### onHoldCallback

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `onHoldCallback` | function | A callback that is called while this Key is held down. Warning: Depending on refresh rate that could be 60+ times per second.

  Source:
    - input/Key.js, line 101

#### onHoldContext

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `onHoldContext` | object | The context under which the onHoldCallback will be called.

  Source:
    - input/Key.js, line 106

#### onUp

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `onUp` | Phaser.Signal | This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again).

  Source:
    - input/Key.js, line 111

#### repeats

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `repeats` | number | If a key is held down this holds down the number of times the key has 'repeated'.

  Default Value:
    - 0
  Source:
    - input/Key.js, line 86

#### shiftKey

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `shiftKey` | boolean | The down state of the SHIFT key, if pressed at the same time as this key.

  Default Value:
    - false
  Source:
    - input/Key.js, line 61

#### timeDown

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `timeDown` | number | The timestamp when the key was last pressed down. This is based on Game.time.now.

  Source:
    - input/Key.js, line 66

#### timeUp

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `timeUp` | number | The timestamp when the key was last released. This is based on Game.time.now.

  Source:
    - input/Key.js, line 80

### Methods

#### justPressed(duration) → {boolean}

  Returns the "just pressed" state of the Key. Just pressed is considered true if the key was pressed down within the duration given (default 250ms)

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `duration` | number | <optional> | 50 | The duration below which the key is considered as being just pressed.

  Source:
    - input/Key.js, line 218

  ##### Returns:

  True if the key is just pressed otherwise false.

  Type
    boolean

#### justReleased(duration) → {boolean}

  Returns the "just released" state of the Key. Just released is considered as being true if the key was released within the duration given (default 250ms)

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `duration` | number | <optional> | 50 | The duration below which the key is considered as being just released.

  Source:
    - input/Key.js, line 232

  ##### Returns:

  True if the key is just released otherwise false.

  Type
    boolean

#### <protected> processKeyDown()

  Called automatically by Phaser.Keyboard.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `event.` | KeyboardEvent |

  Source:
    - input/Key.js, line 134

#### <protected> processKeyUp()

  Called automatically by Phaser.Keyboard.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `event.` | KeyboardEvent |

  Source:
    - input/Key.js, line 165

#### reset(hard)

  Resets the state of this Key. This sets isDown to false, isUp to true, resets the time to be the current time and clears any callbacks associated with the onDown and onUp events and nulls the onHoldCallback if set.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `hard` | boolean | <optional> | true | A soft reset won't reset any events or callbacks that are bound to this Key. A hard reset will.

  Source:
    - input/Key.js, line 191