Per the article you found at: http://unixpapa.com/js/key.html
It looks to me like you really need to be looking at some combination of
event.charCode, event.keyCode, and event.which to distinguish the arrow keys
from the ASCII keys that share the same keycode, and to check the space key
using it's ASCII code.
It seems to me you could do something like:
var charsToIgnore = " \b\r\n";
var ignore = false;
if (event.which == null)
// IE & Opera characters
ignore = charsToIgnore.indexOf(String.fromCharCode(event.keyCode)) >= 0;
else if (event.which != 0 && event.charCode != 0)
// Everyone else characters
ignore = charsToIgnore.indexOf(String.fromCharCode(event.which)) > 0;
else
// special key
k = event.charCode;
// arrow keys
ignore = (k == 37 || k == 38 || k == 39 || k == 40);
}
But we probably also should ask the browser if it supports DOM3 and use that
interface if it does.
On 2010-09-23, at 13:59, Henry Minsky wrote:
> Umm you're right, I guess we need a table of browser->space key mappings
>
> On Thu, Sep 23, 2010 at 1:49 PM, P T Withington <[email protected]>wrote:
>
>> This fix scares me. What key is going to be ignored in other browsers
>> where 32 is _not_ space?
>>
>> Perhaps we need to see: http://www.quirksmode.org/js/keys.html for a
>> solution?
>>
>> On 2010-09-23, at 13:18, Henry Minsky wrote:
>>
>>> Change hqm-20100923-d2m by [email protected] on 2010-09-23 13:15:23
>> EDT
>>> in /Users/hqm/openlaszlo/trunk-clean
>>> for http://svn.openlaszlo.org/openlaszlo/trunk
>>>
>>> Summary: ensure spacebar key does not cause browser scrolling in
>> DHTML/Opera/Safari
>>>
>>> New Features:
>>>
>>> Bugs Fixed: LPP-9381
>>>
>>> Technical Reviewer: max
>>> QA Reviewer: ptw
>>> Doc Reviewer: (pending)
>>>
>>> Documentation:
>>>
>>> Release Notes:
>>>
>>> Overview:
>>>
>>>
>>> Details:
>>>
>>> Add keycode "32" for space key. This works for Opera and Safari.
>> Apparently
>>> there's no cross-browser standard for key codes...
>>>
>>>
>>> Tests:
>>>
>>> + Run examples/components/component_sampler.lzx?lzr=dhtml,
>>> and size browser height short enough so there is a vertical scrollbar.
>>> Click on a checkbox and press spacebar to toggle it's value. The browser
>>> window should not scroll.
>>>
>>> Files:
>>> M WEB-INF/lps/lfc/kernel/dhtml/LzKeyboardKernel.js
>>>
>>>
>>> Changeset:
>> http://svn.openlaszlo.org/openlaszlo/patches/hqm-20100923-d2m.tar
>>
>>
>
>
> --
> Henry Minsky
> Software Architect
> [email protected]