• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

9. Managing Events > 9.10. Determining Which Modifier Keys Were Pressed During ...

Determining Which Modifier Keys Were Pressed During an Event

NN 6, IE 4

Problem

You want to know if the Ctrl, Alt, or Shift modifier keys were being held down during the last event.

Solution

Both the IE and W3C DOM event models use the same set of event object properties to report whether the modifier keys were pressed during the event. The property names are:

  • altKey

  • ctrlKey

  • shiftKey

Another property, metaKey , is active on the Macintosh keyboard as the Command key (but is not supported by IE/Mac). Each property has a value of true or false when an event fires. If the property value is true, the corresponding key was held down at the instant the event fired. The following event function performs one set of actions during an unmodified click, and another action if the Shift key is held down during the click:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint