472,954 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 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 3435
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.