API Docs for: 1.2.7
Show:

kd.Key Class

Defined in: dist/keydrown.js:211

Represents a key on the keyboard. You'll never actually call this method directly; Key Objects for every key that Keydrown supports are created for you when the library is initialized (as in, when the file is loaded). You will, however, use the prototype methods below to bind functions to key states.

Constructor

kd.Key

(
  • keyCode
)

Parameters:

  • keyCode Number

    The keyCode of the key.

Methods

down

(
  • opt_handler
)

Bind a function to be called when the key is held down.

Parameters:

  • opt_handler Function=

    The function to be called when the key is held down. If omitted, this function invokes whatever handler was previously bound.

isDown

() Boolean

Returns whether the key is currently pressed or not.

Returns:

Boolean:

True if the key is down, otherwise false.

press

(
  • opt_handler
  • opt_evt
)

Bind a function to be called when the key is pressed. This handler will not fire again until the key is released — it does not repeat.

Parameters:

  • opt_handler Function=

    The function to be called once when the key is pressed. If omitted, this function invokes whatever handler was previously bound.

  • opt_evt KeyboardEvent=

    If this function is being called by the keydown event handler, this is the raw KeyboardEvent Object provided from the browser. This should generally not be provided by client code.

unbindDown

()

Remove the handler that was bound with down.

unbindPress

()

Remove the handler that was bound with press.

unbindUp

()

Remove the handler that was bound with up.

up

(
  • opt_handler
  • opt_evt
)

Bind a function to be called when the key is released.

Parameters:

  • opt_handler Function=

    The function to be called when the key is released. If omitted, this function invokes whatever handler was previously bound.

  • opt_evt KeyboardEvent=

    If this function is being called by the keyup event handler, this is the raw KeyboardEvent Object provided from the browser. This should generally not be provided by client code.