473,405 Members | 2,373 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,405 software developers and data experts.

Question: firefox keypress event Alt+Shift+any other key

2
Hi,

According to the doc at mozilla, http://developer.mozilla.org/en/docs/DOM:event.charCode, the charCode takes shift into consideration when pressed. I found that to be true for other cases except when Alt+Shift is pressed. For example, the charCode alt+shift+a does not reflect a capitalized a, 'A', or alt+shift+1 does not reflect '!', instead they should 'a' and '1', respectively. Furthermore, I found that when alt+shift is pressed, the shiftKey boolean does get set to true. Does anyone know why this is the case, and any suggestion on how to fix this is appreciated thanks!

Here's an example:
Expand|Select|Wrap|Line Numbers
  1. function foo(e)
  2. {
  3.    if (e.altKey)
  4.       alert("alt key pressed");
  5.  
  6.    if (e.shiftKey)
  7.        alert("shift key pressed");
  8.  
  9.    alert(String.fromCharCode(e.charCode);
  10. }
  11.  
  12. window.addEventListener('keypress', foo, true);
Try pressing key combos of alt+shift+"any other displayable key"

Thanks!!
Jan 3 '08 #1
4 7031
mrhoo
428 256MB
I would write the function like this-
It returns the correct booleans and capitalized letters,
when alt & shift are pressed and another key is pressed and released.

function foo(e){
var str= 'alt key: '+e.altKey+', shift key: '+e.shiftKey+'\n';
var s= e.charCode || e.keyCode;
if(s>= 16 && s<= 18) return;
str+= 'code: '+s+' = '+String.fromCharCode(s);
alert(str);
}

window.addEventListener('keyup', foo, false);
Jan 3 '08 #2
hui11
2
I would write the function like this-
It returns the correct booleans and capitalized letters,
when alt & shift are pressed and another key is pressed and released.

function foo(e){
var str= 'alt key: '+e.altKey+', shift key: '+e.shiftKey+'\n';
var s= e.charCode || e.keyCode;
if(s>= 16 && s<= 18) return;
str+= 'code: '+s+' = '+String.fromCharCode(s);
alert(str);
}

window.addEventListener('keyup', foo, false);
hi mrhoo, thanks for replying... I tried running your code and I am still not getting the upper character with shift pressed. The weird thing is if I hold alt+shift with control and any other key, the upper character is actually alerted. For your information, I am building a plugin for Firefox, and I am running firefox on Ubuntu.

Thanks!!
Jan 3 '08 #3
mrhoo
428 256MB
sorry I couldn't help-
keypress events are the hardest to make work across different browsers,
even the more standard compliant, like firefox, because there really is no standard recommendation for them.

I don't have firefox on linux, but firefox in windows passes the correct letter case with alt or cntrl key pressed with shift.
Jan 3 '08 #4
acoder
16,027 Expert Mod 8TB
On Firefox, keyCode is available onkeyup/down and charCode onkeypress. The 'which' property gives you either of the two. See this useful page for more information.
Jan 5 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mr. x | last post by:
Hello, I want to capture the event when the <ctrl> key is pressed. How can I do that ? Thanks :)
8
by: George Hester | last post by:
When the address bar is highligted? That is nothing on the page is selected. The address bar is selected. Capture keydown or keypress? Any ideas using javascript? Thanks. -- George Hester...
56
by: Karen McAtamney | last post by:
I've been writing http://www.villagefabrics.co.uk since the end of December. It's finally at a stage where I would really appreciate some feedback on the design/code/accessibility and anything else...
0
by: sastwhc | last post by:
sastwhc wrote: > *Hi all > I try change language client side programatically.In my case farsi a > Right to Left Language,the curser direction changed by dir=rtl TAG > changed to correct direction...
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...
4
by: velasquez.m | last post by:
i'm working with visual studio 2005 and have a solution with 16 projects in it. this specific application has a base form with other forms added to it at any area of the application that the...
0
by: colin | last post by:
It seems windows loses the numpad information if you have num lock on and press <alt>+numpad6 is there any way round this with .net ? I realy need all the numpad keys to be used to move and...
3
by: =?Utf-8?B?S1NP?= | last post by:
how can i put some text into these key by C# code ? In the old days you could do it by the PROMPT command i DOS but it seems NOT to work any more - the "change key" facility has disappeared. ...
5
by: Peted | last post by:
Hello, i am lookinf for the best way to trap any alphanumeric keypress in all multi key combminations and execute some code For example , i have a form visible using the form.showdialog...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.