473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

redirect input to accelerator (accessKey)

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.

Longer explanation: I've got a US keyboard and a pseudo
Hungarian/German keyboard (I combined them). The extra keys on the
European keyboard are entered via alt+ctrl+char and
alt+ctrl+shift+char. Now when you define an access key in FF or IE,
the browser tends to care about alt+char being pressed. If ctrl or
shift are there, too, they can come along for the ride. However, if I
have this key combination mapped to something in the operating system,
then the mapping takes priority and the accelerator is ignored.

My question is how to get FF's "default" behaviour of trying the access
key when I'm not in a text input or textarea. The reason I think I
might have a fighting chance is that if I stick an alert('hi mom') in
the onkeydown event handler, then the element with the accelerator is
activated. I just don't know how to bypass having to use the alert.

The example below assumes that alt+ctrl+g maps onto a key which will
display in the input (with my European mapping it maps to §). If it's
not true for you, then you won't see any issues on your system (for
example, on my US keyboard mapping). In that case, one should select
another letter as the access key (go to a text area and start typing
alt+ctrl combinations till something displays), and change the 7th line
in the page below:

<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>&nbsp;&nbsp;
<input type=checkbox id=cb name=cb><br><br>
<button type=button id=btn accesskey=g
onclick="alert('Btn activated')">
<u>G</u>o for it</button>
</form>
<div id=log>Log:</div>
<script type='text/javascript'>
function keyDowned(evt) {
evt = evt || window.event;
document.getElementById('log').innerHTML += "[" +
evt.which + ", " + evt.keyCode + ", " + evt.charCode + "] ";
if (evt.altKey && evt.keyCode>19 && evt.target) &&
evt.target.nodeName!="TEXTAREA" &&
(evt.target.nodeName!="INPUT" ||
evt.target.type!="text")) {
// allows default handling to act?
alert('about to activate');
}
}
</script>
</body></head>
Csaba Gabor from Vienna

Mar 23 '06 #1
1 3457
Csaba Gabor wrote:
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.


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>&nbsp;&nbsp;
<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>

Mar 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Csaba2000 | last post by:
I want to be able to programatically click on the center of an <INPUT type=image ...> element (I only care about IE 5.5+). This should work regardless of whether IE has focus. Normally you would...
6
by: Alex Billerey | last post by:
Hi folks, Not sure that syntax is the right term but anyway... I'm currently working a a new section of a website and I want to make it as accessible as possible - hence the accesskey. On each...
3
by: Jim | last post by:
Hi, How can one put an accesskey on a Select (Drop down box) in a form using XHTML 1.0? It wonąt validate as follows: <select accesskey="r" tabindex="3" name="state" size="1"> I can put an...
0
by: david cheng | last post by:
I am trying to load the pdf document through AccessKey. Here is the code <HTML> <body bottomMargin="0" bgColor="gray" leftMargin="0" topMargin="0" rightMargin="0"> <form id="Form1"...
1
by: WJ | last post by:
How do I set the AccessKey property of a Web Label control on my Asp.Net ? Ex: Lebel Text Name is "Name", I like to see letter "N" underlined so that I can use ALT+N to force the system focus on...
7
by: Csaba Gabor | last post by:
I'd like to detect the shift key when a button is "clicked" in Firefox/Mozilla. If the button is clicked with the mouse, no problem. However, if the onclick event is keyboard originated, then my...
6
by: Haines Brown | last post by:
I use form and input elements just to create an (ugly) navigation button. Now, for accessibility, I provide an accelerator key for it so that the first letter of the value attribute is a link. For...
2
by: killy971 | last post by:
I have been testing different libraries to process XSL transformations on large XML files. The fact is that I read a document from Intel, stating their library (XSLT accelerator) was more twice...
5
by: Lea GRIS | last post by:
Hello, Are there any generic and CSS standard mean of highlighting an accesskey? I only fond a workaround by encapsulating the corresponding letter in a <em></eminside the label. But it is not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.