| re: redirect input to accelerator (accessKey)
Csaba Gabor wrote:[color=blue]
> Short version: if the user types an alt+ctrl+char combination which
> leads to a defined character, but s/he's not in a input(text)/textarea,
> then I'd like that keystroke combination to do the same action that it
> would have done had there not been a defined character.[/color]
Phooey. Somehow an extra right parenthesis crept into the code I gave,
so I redid it to "work" in IE. Only it doesn't. When you do the
ctrl+alt+g combination, the alert does not overcome IE's reluctance on
the accessKey.
Also, in FF if you just press alt+g (outside the textbox), first the
button fires. Then the keyDowned function puts up its alert. When
you dismiss it, the button fires again. Seems mighty suspicious to me.
And that is observable on US keyboard layouts (ie. alt+g is not being
mapped to a printing character). Interestingly, this doesn't happen if
ctrl+alt+g (or its shifted cousin) is not mapped to a printing
character. In that case (using the US layout), keyDowned runs and
subsequently the button is fired.
I don't have any ideas for shoring this up at this point. Even if I
could get around the FF alert business, I have the same (or worse)
problem in IE. Right now it looks like if I want ctrl modifiers upon
click events (even when activated from outside text entry fields), I
have to use a mouse.
Csaba Gabor from Vienna
Here's the corrected page, testable in both IE and FF:
<html><head><title>Accesskey testing</title></head>
<body onkeydown="keyDowned(event)"
onload="document.getElementById('cb').focus()">
<form name=foo action="" method=get>
<input type=text id=txt name=txt>
<input type=checkbox id=cb name=cb><br><br>
<button type=button id=btn accesskey=g
onclick="window.log.innerHTML+='BtnFired '">
<u>G</u>o for it</button>
</form>
<div id=log>Log:</div>
<script type='text/javascript'>
window.log=document.getElementById('log');
function keyDowned(evt) {
evt = evt || window.event;
var trgt = evt.target || evt.srcElement;
var log = document.getElementById('log');
log.innerHTML += "[" + evt.keyCode;
if (typeof(evt.which)=="number")
log.innerHTML += ", " + evt.which;
if (typeof(evt.charCode)=="number")
log.innerHTML += ", " + evt.charCode;
log.innerHTML += ", " + (trgt.type || trgt.nodeName) + "] ";
if (evt.altKey && evt.keyCode>19 && trgt.nodeName) {
if (trgt.nodeName!="TEXTAREA" &&
(trgt.nodeName!="INPUT" ||
trgt.type!="text")) {
// allows default handling to act?
alert('about to activate');
} }
}
</script>
</body></head> |