[key] Mac is sending 0 keycodes for some keys (keydown/keyup)

RESOLVED FIXED in mozilla1.9alpha8



19 years ago
11 years ago


(Reporter: Brade, Assigned: jaas)


Dependency tree / graph
Bug Flags:
blocking1.9 +

Firefox Tracking Flags

(Not tracked)




(4 attachments, 3 obsolete attachments)



19 years ago
Based on Rods' example (see url above), I can see that the Mac isn't always 
sending a keycode for some keys for keydown/keyup events.
Here are a few of the keys which don't work:
  shift-1 thru shift-0
  -, shift--
  any key with the option modifier

Comment 1

19 years ago
setting to m18
Target Milestone: --- → M18


19 years ago

Comment 2

19 years ago
this is related to the other key event issues, providing the correct key event 
functions for users is critical
Keywords: correctness, nsbeta3

Comment 3

19 years ago
setting to nsbeta3+
Whiteboard: nsbeta3+


19 years ago
Summary: Mac is sending 0 for keycodes for some keys (keydown/keyup) → [key] Mac is sending 0 keycodes for some keys (keydown/keyup)


19 years ago
Whiteboard: nsbeta3+ → [nsbeta3+]

Comment 4

19 years ago
adding priority to status whiteboard, not *that* complicated but it'll take time 
to get it right
Priority: P3 → P2
Whiteboard: [nsbeta3+] → [nsbeta3+][p:2]

Comment 5

19 years ago
reassign to akkana; akkana--we probably need to do something hacky like create a 
table similar to how gtk works.  I don't have any other ideas.  :-/
Assignee: brade → akkana

Comment 6

19 years ago
Actually, joki recently gave me the go-ahead to put those missing symbols into
nsGUIEvent/nsIDOMKeyEvent.  I'm hoping to overhaul those files soon (so we only
have the list of keycodes in one place!), and if I have time, I'll also change
the linux key event code, and, if I can figure out how :-), I'll also do the mac
event code, which would be the best fix to this bug.

Comment 7

19 years ago
Per beppe: setting this to nsbeta3- and reassigning back to brade.
Assignee: akkana → brade
Whiteboard: [nsbeta3+][p:2] → [nsbeta3-]
Target Milestone: M18 → M19


19 years ago

Comment 8

19 years ago
this is correctness of events, low risk fix
reviewed by Bijal and beppe, setting to nsbeta3+, p2
Severity: normal → major
Whiteboard: [nsbeta3-] → [nsbeta3+][p:2]

Comment 9

19 years ago
pdtp4.  It's not clear there is any user visible impact for this bug.  If it
exists and is merely obscure, please clarify and bring it back to the pdt.
Priority: P2 → P3
Whiteboard: [nsbeta3+][p:2] → [nsbeta3+][p:2][pdtp4]
Target Milestone: M19 → Future

Comment 10

19 years ago
on the mac many key events do not work, if it is acceptable for key events to
not work on the mac -- see the first entry in this bug -- then please remark as
pdt priority of your choice and future it. Personally, my opinion is that is a
grave mistake.
Whiteboard: [nsbeta3+][p:2][pdtp4] → [nsbeta3+][p:2]
Target Milestone: Future → M19

Comment 11

19 years ago
Incidentally, we're expecting char codes for these characters, not key codes,
right?  All the examples given are printable characters.

Comment 12

19 years ago
setting to nsbeta3- and setting to future, there are menu items that can be
used, which is a viable workaround
Whiteboard: [nsbeta3+][p:2] → [nsbeta3-]
Target Milestone: M19 → Future

Comment 13

19 years ago
To paraphrase someone, the future is now.  Can we revisit this bug and figure out 
if it's going to make the next train?
okay, clearing the milestone so that we reconsider this.
Keywords: nsbeta3
Whiteboard: [nsbeta3-]
Target Milestone: Future → ---

Comment 15

19 years ago
probably won't make this train unless someone else picks it up; milestone-->
Keywords: helpwanted
Target Milestone: --- → Future

Comment 16

18 years ago
removing myself from the cc list

Comment 17

17 years ago
Any relation to bug 111335, bug 148130? Does this block bug 122479?

Comment 18

17 years ago
This bug is about the keydown and keyup events on Mac sending a 0 keycode
instead of the proper value.  The event is still being sent (not that I've
verified lately).

Bug 111335 is about the events not being received at all.  If that is true, it
will block verification of this bug since you need to see the event before you
can look at the keycode for it.

This particular bug is unrelated to bug 122479 (accesskey usage on Mac). 
Accesskey modifier is "Control" and this bug is about shifted key events. 
(Possibly both are blocked by 111335?)

Comment 19

17 years ago
This bug is effecting all peoplesoft customers on mac os. Since many of our 
users jobs require data entry, having hot keys is a major plus for them. Since 
we cannot get the keycode with the alt key now means that none of out hot keys 
will work on NS 7 on mac. Do we know when this is planned to be fixed. Is there 
a workaround we could use. 

Comment 20

17 years ago
Eamon_Gaffney@peoplesoft.com (comment 19):
By "hot keys" do you mean accesskeys like for forms?  On the Mac, those are
accessed with Control key not the alt key.  If you have a
case where the accesskeys don't work on Macintosh, please file a new mozilla bug
with the url or a sample html file and cc me (brade@netscape.com).

Comment 21

17 years ago
hi brade
your question was "what do I mean by access keys"
I mean that our system has a number of hot keys to allow users to, say, add a 
new row with the Alt+7 button. However no matter what combination I tried the 
evt.keycode always returns 0 and as a result this makes it difficult to resolve 
what key the user pressed. 

Comment 22

17 years ago
Eamon_Gaffney@peoplesoft.com (comment 21): you could try looking at the keyevent
on keypress instead of keydown (looking at event.charCode).  Perhaps paste in a
snippet of your html/js?

Comment 23

17 years ago
save this file as  a html and view in NS 7 on mac. You will see that when you
press alt+7 the alert message says the keycode is 0 it should be 55 if you try
in windows env.
This bug is targeted at a Mac classic platform/OS, which is no longer supported
by mozilla.org. Please re-target it to another platform/OS if this bug applies
there as well or resolve this bug.

I will resolve this bug as WONTFIX in four weeks if no action has been taken.
To filter this and similar messages out, please filter for "mac_cla_reorg".


16 years ago
OS: Mac System 8.5 → All
This is still an issue on Mac OS X 10 [Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.9a1) Gecko/20060304 SeaMonkey/1.5a].
*** Bug 300678 has been marked as a duplicate of this bug. ***


13 years ago
Blocks: tibco

Comment 27

13 years ago
I've been using this doc to see KeyEvent values. As it stands, just using 'Shift' w/ a key does not work. This page works reasonably well w/ Safari/Firefox.


Comment 28

12 years ago
Still happening in Mac 10.4/Intel Gecko 20070309 Firefox Any modifier key combined with number keys row 


reports keycode 0 on a keydown event. Was attempting to use for accessibility shortcuts via a generalized keystroke to function/method mapping system.
-> Default Asignee

This has sat for long enough. Josh, is this going to be an issue with the new Cocoa key handling?
Assignee: brade → nobody
QA Contact: bugzilla → keyboard.navigation

Comment 30

12 years ago
This still happens under Cocoa.
Changing component, then, and requesting blocking1.9. I know this affects the TIBCO General Interface toolkit, possibly others.

Jesse, can you comment on the difficulties this bug causes so that drivers can triage properly?
Assignee: nobody → joshmoz
Component: Keyboard: Navigation → Widget: Cocoa
Flags: blocking1.9?
OS: All → Mac OS X
QA Contact: keyboard.navigation → cocoa
Hardware: Macintosh → All
The mission of TIBCO General Interface is to web applications with the look and feel of desktop graphical user interface application. To that end, we implement many features typically found in Windows and Mac OS X, such as key accelerators. For example, when you type Ctrl+S in the GI IDE, the component you are working on is saved. We have been able to implement key accelerators on Internet Explorer and Firefox for Windows without a problem. We capture the keydown event and look at the keyCode field of the event object. We use code that I'll add as an attachment (keyCodeToString.js). The problem is that on Firefox on Mac OS X, some keys are reported incorrectly. For example ctrl+. is reported as ctrl+n. (See https://bugzilla.mozilla.org/show_bug.cgi?id=44259). Moreover, the mapper error from key to keyCode is not recoverable because ctrl+. and ctrl+n report the same keyCode value. 



12 years ago
Flags: blocking1.9? → blocking1.9+

Comment 35

12 years ago
Posted patch fix v1.0 (obsolete) — Splinter Review
This fixes a whole bunch of key codes, almost everything in this bug plus a bunch more. I didn't fix the ones that don't have a clear definition according to DOM specs.

Comment 36

12 years ago
Posted patch fix v1.0.1 (obsolete) — Splinter Review
oops, I forgot to diff part of the patch
Attachment #268446 - Attachment is obsolete: true
Comment on attachment 268451 [details] [diff] [review]
fix v1.0.1

>     default:
>       if (aKeyEvent->isControl)
>         charCode += 64;

Is this still necessary now that you use charactersIgnoringModifiers? Did that break Control-key handling?

>+          if (charCode >= 'a' && charCode <= 'z') // lowercase
>             geckoKeyCode = toupper(charCode);
>           else if (charCode >= 'A' && charCode <= 'Z') // uppercase
>             geckoKeyCode = charCode;

I know you didn't write this, but couldn't you optimize this function by moving the common ASCII char cases to the top of the function?

Comment 38

12 years ago
Posted patch fix v1.1 (obsolete) — Splinter Review
This removes the nasty control key logic ben mentioned because that causes some bugs and looks like a mistake made back in the original event branch back in 1999.

This also adds support for colon.
Attachment #268451 - Attachment is obsolete: true
Attachment #268569 - Flags: review?(nick.kreeger)

Comment 39

12 years ago
Comment on attachment 268569 [details] [diff] [review]
fix v1.1

Looks good to me. Josh and I couldn't think of a reason the +64 call was there. When we looked up the blamelog, that code landed in 1999.
Attachment #268569 - Flags: review?(nick.kreeger) → review+

Comment 40

12 years ago
Not code I'm familiar with (I don't know cocoa key events) but the +64 is presumably because ctrl + A (ascii 65) is ascii 1, and so on.
Presumably this is no longer needed for the current code, if it's already getting a char code of A rather than 1 from the native key event.


12 years ago
Attachment #268569 - Flags: superreview?(dbaron)
I'm not an appropriate reviewer for this -- you should probably ask jst or smaug.


12 years ago
Attachment #268569 - Flags: superreview?(dbaron) → superreview?(jst)


12 years ago
Target Milestone: Future → mozilla1.9alpha6

Comment 42

12 years ago
I put the URL for the spec I was basing my key event values on in the URL field of this bug.

Comment 43

12 years ago
Another note on my choice of DOM key code values - I checked with IE, WebKit and Opera and Opera seems to be the only browser that doesn't just assign seemingly random numbers to anything beyond alphanumeric keys. Thus, I made sure my work matched up as closely as possible with Opera's implementation, and their implementation matches the WD DOM 2 spec pretty closely.

IE and WebKit don't match up with each other or Opera or the WD spec, as far as I can tell they just made up their own key codes.


12 years ago
Attachment #268569 - Flags: review?(Olli.Pettay)
Comment on attachment 268569 [details] [diff] [review]
fix v1.1

Opera gives the same 0x2d for INSERT as we do currently, so I wouldn't change it.
(Tested on Linux/trunk and Opera 9.2)

(And as far as I see, Opera doesn't follow the old DOM 2 WD elsewhere either. For example pressing '+' in the keypad gives 0x2b, not 0x6B nor 0x0209)

And if you add support for new VK_s, those should be, IMO, supported in all major platforms, if possible.
And http://lxr.mozilla.org/seamonkey/source/content/xbl/src/nsXBLPrototypeHandler.cpp#606 should be updated too.

Slightly modified test http://mozilla.pettay.fi/moztests/showkeys.html
Attachment #268569 - Flags: review?(Olli.Pettay) → review-


12 years ago
Attachment #268569 - Flags: superreview?(jst)


12 years ago
Target Milestone: mozilla1.9alpha6 → mozilla1.9beta1

Comment 45

12 years ago
Posted patch fix v2.0Splinter Review
This is very similar to the patch from before, but I am not trying to support key codes that aren't already supported in gecko. I think we should file separate bugs for any particular key codes not fixed by this patch.
Attachment #268569 - Attachment is obsolete: true
Attachment #270134 - Flags: review?(nick.kreeger)

Comment 46

12 years ago
Comment on attachment 270134 [details] [diff] [review]
fix v2.0

Looks good to me.
Attachment #270134 - Flags: review?(nick.kreeger) → review+


12 years ago
Attachment #270134 - Flags: superreview?(mikepinkerton)
Comment on attachment 270134 [details] [diff] [review]
fix v2.0


did you test the charactersIgnoringModifiers change on non-roman languages and languages with accents (french, spanish, etc)?
Attachment #270134 - Flags: superreview?(mikepinkerton) → superreview+
Hi, the following key codes work on Internet Explorer and Fx for Windows and Fx for Mac when no modifier keys are held down:

  Event.KEY_ALT = 18;
  Event.KEY_ARROW_DOWN = 40;
  Event.KEY_ARROW_LEFT = 37;
  Event.KEY_ARROW_RIGHT = 39;
  Event.KEY_ARROW_UP = 38;
  Event.KEY_BACKSPACE = 8;
  Event.KEY_CONTROL = 17;
  Event.KEY_DELETE = 46;
  Event.KEY_END = 35;
  Event.KEY_ENTER = 13;
  Event.KEY_ESCAPE = 27;
  Event.KEY_HOME = 36;
  Event.KEY_INSERT = 45;
  Event.KEY_PAGE_DOWN = 34;
  Event.KEY_PAGE_UP = 33;
  Event.KEY_SHIFT = 16;
  Event.KEY_SPACE = 32;
  Event.KEY_TAB = 9;
  Event.KEY_0 = 48;
  Event.KEY_9 = 57;
  Event.KEY_A = 65;
  Event.KEY_Z = 90;
  Event.KEY_F1 = 112;
  Event.KEY_F15 = 126;
  Event.KEY_NP0 = 96;  // number pad key variants
  Event.KEY_NP9 = 105;
  Event.KEY_NPDIV = 111;
  Event.KEY_NPMUL = 106;
  Event.KEY_NPSUB = 109;
  Event.KEY_NPADD = 107;
  Event.KEY_NPDEC = 110;

Comment 49

12 years ago
landed on trunk

I did some testing on Japanese and accented characters and it worked fine.
Closed: 12 years ago
Resolution: --- → FIXED

Comment 50

11 years ago
I've been watching this bug on and off for eight years now and just tested it in the recently released Macintosh version of Firefox 3.0. Sorry guys, it is only partially fixed.

Zero keycodes are still returned for
shift-- (_)
shift-` (~)
shift-\ (|)
shift-, (<)
shift-. (>)
shift-/ (?)
shift-; (:)

In addition, though shift-= (+) no longer returns a zero keycode, it now returns an incorrect keycode, 107 instead of 61.  From the response above, I guess this is the keycode for the number pad plus key, not the keyboard plus key.

Keys typed with ALT do work now, as do all the shifted number keys and the unshifted - key.

Comment 51

11 years ago
Reopening per comment 50. The testcase attachment 246186 [details] continues to demonstrate the problems Jan describes.
Resolution: FIXED → ---
Greg, Jan: I think you should open a new bug for that. It sounds like a regression since this apparently was working a year ago.

Comment 53

11 years ago
(In reply to comment #52)
> Greg, Jan: I think you should open a new bug for that. It sounds like a
> regression since this apparently was working a year ago.

I don’t think it’s a regression. Josh landed the fix on trunk on 2007-06-29. The earliest Mac GranParadiso build that contains the fix (2007080209/3.0a7) still fails the cases in comment 50.

Anyway, if you still think it should be filed as a new bug let me know and I’ll file it.
Since the bulk of the keycodes were fixed, it's easier to track (and fix) the overlooked cases in a focused, separate bug.


11 years ago
Blocks: 448434

Comment 55

11 years ago
(In reply to comment #54)
> Since the bulk of the keycodes were fixed, it's easier to track (and fix) the
> overlooked cases in a focused, separate bug.

Filed as bug 448434.
Closed: 12 years ago11 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.