473,473 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Detect shift-character keypress

Hi all,

I am becoming a little stressed with the age-old problem of detecting when a
user types (for example) a quote character ("). On a UK keyboard, I can look
for a 2 + shift mask; on US, single quote + shift mask.

I don't want to have to know every single international keyboard layout just
to know when a shifted character has been entered. If anybody has any ideas
to share, I'd be very grateful!

Thanks in advance,

Chris.
Jul 23 '05 #1
5 2446
VK
I'm missing the root of your problem.

" (double quote) has ASCII-ISO code 34 (hex 22), and this fact has nothing
to do with the current keyboard layout. The same for the rest of ASCII table
(low 127 chars).

What is your actual aim?
Jul 23 '05 #2
Hi VK, thanks for the fast response.

I have a function that is called onMouseDown and I want to know when the
user types a quote, even if not currently in a text editing element.

I can detect that a key has been pressed and can, of course, get the keyCode
and whether shift was pressed. I don't seem to be able to get the ASCII
code, which -- as you point out -- is exactly what I want.

Here's the code:

document.onkeydown = keyIsDown;
function keyIsDown(e){
if(!e)
e = window.event;

window.status = "key down: " + String.fromCharCode(e.keycode) + " ( " +
e.keyCode + ")";
}

If I press '2' , I get 2 (50); if I press '"', I also get 2 (50).

Please tell me I'm missing something simple!

Cheers...

Chris.

"VK" <sc**********@yahoo.com> wrote in message
news:41***********************@news.freenet.de...
I'm missing the root of your problem.

" (double quote) has ASCII-ISO code 34 (hex 22), and this fact has nothing
to do with the current keyboard layout. The same for the rest of ASCII table (low 127 chars).

What is your actual aim?

Jul 23 '05 #3
Sorry, onMouseDown should be onkeydown!
Jul 23 '05 #4
On 13/10/04 5:41 pm, Chris Williams wrote:
If I press '2' , I get 2 (50); if I press '"', I also get 2 (50).


The onkeydown event will check for *any* key being pressed. That includes
the shift key. So when you press your "2" key, a totally separate event is
fired.

Use the onkeypress event instead

document.onkeypress = checkKey;
function checkKey(e) {
if (!e) e = window.event;
window.status = "key down: " + String.fromCharCode(e.keyCode) + " ( " +
e.keyCode + ")";
}

Phil
--
Philip Ronan
ph***********@virgin.net
(Please remove the "z"s if replying by email)
Jul 23 '05 #5
Thanks very much Philip -- I think my confusion arose after creating
functions to capture mouse events, using onmousedown. I think I more-or-less
automatically created what I thought would be the keyboard equivalent, which
did not work!

Thanks for taking the time to reply, I've got this sorted now.

Cheers,

Chris.

"Philip Ronan" <ph***********@virgin.net> wrote in message
news:BD93454E.23A30%ph***********@virgin.net...
On 13/10/04 5:41 pm, Chris Williams wrote:
If I press '2' , I get 2 (50); if I press '"', I also get 2 (50).


The onkeydown event will check for *any* key being pressed. That includes
the shift key. So when you press your "2" key, a totally separate event is
fired.

Use the onkeypress event instead

document.onkeypress = checkKey;
function checkKey(e) {
if (!e) e = window.event;
window.status = "key down: " + String.fromCharCode(e.keyCode) + " ( " +
e.keyCode + ")";
}

Phil
--
Philip Ronan
ph***********@virgin.net
(Please remove the "z"s if replying by email)

Jul 23 '05 #6

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

Similar topics

6
by: Rune | last post by:
Hey I'm trying to build a gui application and need to know if the user is actually holding down the shift or ctrl key. That is, if the user currently is holding down the shift key. In pseudo...
1
by: funtoosh | last post by:
Hi Scenario: I have a shell script e.g. a.bash This script wraps a program called "generate" like this: generate > /tmp/y.txt 2>&1 # both stdout and stderr r redirected to y.txt
43
by: Mehta Shailendrakumar | last post by:
Hello, Can anyone suggest me operator to perform arithmetic shift in C? May it be for a perticular compiler. Thank you in advance. Regards, Shailendra
3
by: ngreplies | last post by:
I have a need for an extra facility to be available when the user presses the SHIFT key whilst clicking on either a Button Control or a textbox. I am using both VB6 and VB.NET2002. Could anyone...
2
by: Steph. | last post by:
Hi, A simple question : How can I detect if the CTRL key is pressed when User click on a control ? Thanks, Steph.
0
by: Martijn Mulder | last post by:
/* I override IsInputKey() to direct the Arrow Keys (Cursor Keys) to my custom System.Windows.Forms.Control. But, holding down the Shift-Key prevents the Arrow Keys from coming through. How can...
3
by: Amy Smith | last post by:
Hello there, I am having a small problem which been challenging me for few days and need help or advice. I am trying to calculate the day-shift for employees based on the time they started and...
13
by: halbenca | last post by:
Is this possible with Javascript in anyway? :)
1
by: mark4asp | last post by:
<!-- // How to detect the rendering mode which the browser is currently in (works for IE6). // Ctrl+Shift+s displays indicates whether the browser is in quirks or standards mode. // Detect...
3
by: Pietro | last post by:
Hi all, First of all I'd like to thank you very very much ,as finally after many years of searching,I could find a code to disable/enable the shift key,but actually i cannot use the code as I'm...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.