Open Bug 308565 Opened 15 years ago Updated 10 years ago

event.altKey is always false for onkeypress on Mac


(Core :: Widget: Cocoa, defect)

Not set




(Reporter: adam.winer, Unassigned)


(Depends on 1 open bug, Blocks 1 open bug)



(1 file)

132 bytes, text/html
User-Agent:       Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b4) Gecko/20050721 Firefox/1.0+
Build Identifier: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b4) Gecko/20050721 Firefox/1.0+

In the following HTML snippet:

<input type="text" onkeypress="alert('alt? ' + event.altKey)">

... entering the field and hitting the "alt-A" keystroke (aka option-A) on the
Mac just shows "alt? false".  This correctly shows "alt? true" on Safari.  It
does work for onkeydown and onkeyup.

Reproducible: Always

Steps to Reproduce:
1. Add the following to a document:
 <input type="text" onkeypress="alert('alt? ' + event.altKey)">
2. Enter the field.
3. press option-a

Actual Results:  
You see "alt? false" in an alert.

Expected Results:  
You should have seen "alt? true in an alert.

MacOS 10.4.2
Repros in Firefox 1.0.3 and Deerpark alpha 2
Assignee: nobody → events
Component: General → DOM: Events
Product: Firefox → Core
QA Contact: general → ian
Version: unspecified → 1.8 Branch
see bug 300678 : that piece of JS code correctly determines the state of the
altkey (using onkeydown)
Mac widgetry issue.
Assignee: events → joshmoz
Component: DOM: Events → Widget: Mac
QA Contact: ian → mac
Depends on: 280805
it seems like one must use alt+(ctrl|cmd) to get a "true" value here.  for keycode 18 (alt) in about:config prefs. only the ctrl+alt variant works, though.

there must be some way to allow plain old (alt) as a modifier key...
this should probably get marked as a duplicate of bug 44259.
Why?  It doesn't seem very related to me...
(In reply to comment #5)
> Why?  It doesn't seem very related to me...

yeah, maybe not.  i assumed that fixing bug 300678 would also take care of this one, and that was just marked as a dupe of 44259, ergo...
If it's not a dupe, then it's definitely a bug.  -->Cocoa
Component: Widget: Mac → Widget: Cocoa
Ever confirmed: true
QA Contact: mac → cocoa
Version: 1.8 Branch → Trunk
Attached file test case
Assignee: joshmoz → nobody
You need to log in before you can comment on or make changes to this bug.