Javascript Madness Intro | Mouse Events | Key Events

Javascript Madness: Mouse and Key Events in iCab 3

Jan Wolter
June 23, 2008

1. Introduction

My reports comparing mouse and key events in various browsers used to include material on the rather obscure iCab browser. iCab 3 used it's own independently developed rendering engine, and thus had it's own unique collection of bugs, which were worth documenting. iCab 4, however, switched to using Apple WebKit, the same rendering engine used in Safari, and, from a web developer's point of view, is now pretty much identical to Safari.

I don't think web developers are going to have any lasting interest in the peculiarities of iCab 3's event handling code, so I have removed all discussion of it from the main documents. In the unlikely event that anyone ever cares again, I've stuck the removed data here. Much of this document consists of rows and columns clipped out of the tables in the main documents referenced above.

This data is based on tests done with iCab version 3.0.3. That was not the final release of iCab 3, but I have no plans to ever update this document.

2. Mouse Events

2.1. Mouse Buttons and Default Events

Since iCab is a Macintosh browser, all questions relating to middle and right mouse buttons are irrelevant since Macintosh computers don't usually have middle or right mouse buttons. Default actions of the left mouse button can, of course, be disabled.

2.2. Event Triggering - Single Clicks

Single clicks of the left mouse button generate the normal events. There are no other mouse buttons.

2.3. Event Triggering - Double Clicks

Double clicks of iCab's left mouse button gave the same events as Konqueror and Safari 1.3:
iCab 3
DOWN mousedown
UP mouseup
click
DOWN mousedown
UP mouseup
dblclick

2.4. Identifying Mouse Buttons

When a mouse event occurs in iCab 3, event.which is 1 and event.button is 0. This agrees with the values Gecko returns for the left mouse button.

3. Key Events

3.1. Event Triggering

Key events were mostly normal in iCab 3, but no events were triggered when modifier keys ([Shift], [Control], [Alt], etc) were pressed.

When keys were held down long enough to autorepeat, iCab 3 generated three events for each autorepeat.

Browser Events triggered on each autoreapeat
iCab 3 keyup
keydown
keypress

If you are installing your own handlers for key events, then sometimes you won't want the browser default action to occur (such as having the character appear in a text entry area). To prevent this in iCab, you need to surpress defaults on the keydown event.

Browser Which event handlers need to suppress defaults to prevent key from appearing in text box
iCab 3 keydown

If you suppress defaults on the keydown event then neither the keypress nor the keyup event will occur.

Browser Side effect if keydown handler returns false
iCab 3 keypress event never occurs.
keyup event never occurs.

This is actually problematical. If you want to suppress default handling of the key, you need the keydown handler to return false. But if you do that, both keypress and keyup events disappear. So you can't do either keypress handling or keyup.

So, in summary, if we press the [Shift] key, then press the [A] key, holding it down long enough to auto-repeat just once, then release [A], and the release [Shift] we see the events shown below. Events marked in red do not occur if there is a keydown handler that returns false.

iCab 3
[Shift] pressed  
[A] pressed keydown
keypress
[A] autorepeats keyup
keydown
keypress
[A] released keyup
[Shift] released  
This is, of course, different than any other browser.

3.2. Key Codes

In our main document on key events we defined several sets of keycode values returned by different browsers to identify which key was struck. iCab 3 returned its own unique combination of these.
event.keyCode event.which event.charCode
iCab 3 keydown/keyup: Pseudo-ASCII code

keypress: ASCII code

same as event.keyCode ASCII code
Many browsers return ambiguous values for arrow keys on keypress events. iCab avoided this problem, but the values it returned were unlike those returned by any other browser.
Browser "ASCII" values sent for arrow keys
up arrow down arrow left arrow right arrow
iCab 3 30312829

Weirdly, iCab three perfectly emulated the Gecko bug in which zero keycode values were returned for many symbol keys on keydown and keyup events. Characters that give a zero keycode when typed include those listed below, as well as any key when the Alt/Option key is held down.

- _ ~ ! @ # $ % ^ & * ( ) + | : < > ?