Main Page

Detecting Shift, Alt, Ctrl

Detecting Shift, Alt, Ctrl
To detect if the Shift, Alt, or Ctrl keys are pressed, both IE and the DOM can do the following:
var bShift = oEvent.shiftKey;
var bAlt = oEvent.altKey;
var bCtrl = oEvent.ctrlKey;
Each of these properties contains a Boolean value indicating whether the key is being pressed (each of
these keys also fires a
event enabling you to retrieve its
Getting the client coordinates
During mouse events, you can retrieve the location of the mouse cursor in relation to the client area by
using the
var iClientX = oEvent.clientX;
var iClientY = oEvent.clientY;
The client area is the part of the window that displays the Web page (see Figure 9-7). These properties
tell you how far from the edge (in pixels) of that area the mouse is located.
Figure 9-7
Client Area
All about Events
12_579088 ch09.qxd 3/28/05 11:39 AM Page 275

JavaScript EditorFree JavaScript Editor     Ajax Editor