PencilCoder

Event Objects!

Goals:

  • Process information about events using event objects
  • Explore the keypress and keyup events

Coding Snippets:

  • coding snippets
  • Event listeners automatically pass information about each event to the event handler, in the form of an event object
  • Access the event object by adding a single argument to the event handler. Common names for this argument are e, evt, and event.
  • Event objects have many other properties besides key, some of which are explored below.

Math and Computer Concepts:

  • The key event object's keyCode property provides a numeric value representing that key (similar to ASCII); the shiftKey, metaKey, ctrlKey, and altKey properties use boolean values to record the status of modifier keys at the time of the event; and the timeStamp property records how many milliseconds elapsed since the program started when the event fires.
  • keypress differs from keydown primarily in that the value of its key property is case sensitive. There are additional, more nuanced differences too, such as that the keypress event doesn't fire for keystrokes that don't produce visible output on the screen (e.g., shift or control ) and only keyup events fire for the delete key.

Activities:

Save each of the following in a folder called EventObjects.