September 11, 2000 - Detecting a Modifier Key
September 11, 2000|
Detecting a Modifier Key
Tips: September 2000
Yehuda Shiran, Ph.D.
You can detect if a modifier was pressed by simply checking if the appropriate property is
true. Unlike Internet Explorer 4.0x and above, Navigator 4.0x's modifier keys are reflected in one property:
modifiers. This property must be tested against a constant property of the
Event object with the bitwise AND operator in order to find out which modifier keys were pressed when the event occurred. For example, the expression:
e.modifiers & Event.ALT_MASK
evaluates to a Boolean value indicating the state of the Alt key when the event occurred. The four masks are:
The following code is included in the current page:
Notice how we detect the browser: Netscape Navigator supports
window.Event while Internet Explorer does not. Try now to type upper-case and lower-case character. Lower-case letter go unnoticed. Upper case characters trigger a proper alert box.
Learn more about the event model in Column 11, The Cross-Browser Event Model.