event handlers can accept a parameter called the event object
this object has information about the event
for example, which element was clicked on
which button or key was pressed
properties and methods vary depending on the type of event
this parameter is usually called event or simply e
Key Events
keydown and keyup events
keydown will repeat if held
event.key holds a string with the value that the key would type
boolean properties for modifier keys:
event.shiftKey
event.ctrlKey
event.altKey
event.metaKey (Windows key or Mac Command key)
Key Events Continued …
event occurs on element that has focus (or document.body)
if you want to capture all keystrokes, use window.addEventListener()
window. is optional since it is the global object
Note: the keypress event is depricated
Key Event Properties
event.key (String) The key value of the key represented by the event. If the value has a printed representation, this value is that character (Eg. "a"). Otherwise, it describes the key (Eg. "Escape").
event.code (String) Holds a string that identifies the physical key being pressed. The value is not affected by the current keyboard layout or modifier state, so a particular key will always return the same value.
there are other depricated properties that should be avoided