473,804 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

capture event when ctrl key is pressed

Hello,
I want to capture the event when the <ctrl> key is pressed.

How can I do that ?

Thanks :)
Jul 20 '05 #1
3 34346
"Mr. x" wrote on 14/11/2003:
Hello,
I want to capture the event when the <ctrl> key is pressed.

How can I do that ?


This is under IE 6 (I don't have any other browsers, so someone else
will have to chip in).

A onkeydown event is fired when the CTRL key is pressed, but the
event.which and event.modifiers properties are undefined (even when a
letter key is pressed). This means that there is no reliable way to
detect it. The onkeypress event doesn't work with modifier keys
(ctrl, alt, shift, etc).

Do Mac keyboards even have CTRL keys?

Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.u k (remove [no-spam] to reply)
Jul 20 '05 #2
Michael Winter hu kiteb:
"Mr. x" wrote on 14/11/2003:
Hello,
I want to capture the event when the <ctrl> key is pressed.

How can I do that ?


This is under IE 6 (I don't have any other browsers, so someone else
will have to chip in).

A onkeydown event is fired when the CTRL key is pressed, but the
event.which and event.modifiers properties are undefined (even when a
letter key is pressed). This means that there is no reliable way to
detect it. The onkeypress event doesn't work with modifier keys
(ctrl, alt, shift, etc).


Both navigator 7 and explorer 6 can detect the onkeyup event, and do
recognise the control key. onkeydown and onkeypress may also be
supported. However, control+[key] combo keystrokes are rather more
difficult to detect. I haven't tried.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #3
ckohtz
1 New Member
This works completely in Mozilla (ns), have problems in IE when only using the ev.ctrlKey && ev.keyCode, it's like it won't capture the ctrl unless the shift or alt key are pressed too. Annoying!

Expand|Select|Wrap|Line Numbers
  1. var captureKeys = function(ev) {
  2.     ev = ev || window.event;             // gets the event in ie or ns
  3.     kCode = ev.keyCode || ev.which;   // gets the keycode in ie or ns
  4.  
  5.     /* in ie, when pressing the ctrl + shift + key, it gives the key code for the capitalized key (probably because shift is pressed) 
  6.        in ns pressing ctrl, shift and another key doesn't change the keycode
  7.        thus, the || and two different numbers */
  8.  
  9.     if (ev.ctrlKey && ev.shiftKey && kCode == 19 || ev.ctrlKey && ev.shiftKey && kCode == 83) {    // ctrl+alt+s
  10.                 saveFunction() // another function that does something
  11.         return false;  // make it so the browser ignores key combo
  12.     }
  13.     if (ev.ctrlKey && kCode == 119) { // ctrl+w
  14.         closeWin();  // run your own script to close the window 
  15.                                  // doesn't work in ie, ie just closes the window
  16.         return false;
  17.     }
  18. }
and then put this in the body tag...

onload="documen t.onkeypress=ca ptureKeys;"
May 4 '06 #4

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

Similar topics

2
10294
by: Boaz Ben-Porat | last post by:
Is there any way to determine if the CTRL key is pressed from a MouseDown event on a DataGrid ? TIA Boaz ben-Porat DataPharm a/s Denmark
1
5787
by: karunakar | last post by:
Hi all Just i want capture the with "Ctrl" (Key bord function) + any F1 or F4 In windows application How can capture the event in C# .net Regards, Venu
5
3144
by: ewillyb | last post by:
Hi, ASP.NET has some interesting behavior when the user hits the Enter key. If there are multiple ASP:Buttons (rendered as HTML submits) on the form, when the user hits enter, the first button's click event will fire and the page will submit. I have a series of pages with Previous and Next navigational Btns. The Previous button is the first button, so when the user hits enter, the previous page is served up. Enter should result in...
7
62049
by: Bob Achgill | last post by:
When I use the code for KeyPress to capture pressing a certain key for processing on a form with no Text Box it works. But when I try the same code on my application that has text boxes it does does not work. How can I capture the cursor left and right keys for processing?
2
7056
by: Don | last post by:
It took me a while to find this code, so I decided to post it here for others who might also be looking for a way to trap tab key presses. You can extend a control and place this code in it to raise a custom TabKeyDown event. Here is an example of how you might extend a TextBox control to provide this event: Public Class TextBoxEx Inherits TextBox
4
3976
by: t3projects | last post by:
I'm working on controlling a windows media player I'm trying to figure out how to control it with keys like CTRL+SHIFT+P to play it. The problem is that I don't know how to capture all three at the same time. I'm ONLY supporting IE because that's what the client only want's supported. I have been reading through the forums but nothing about capturing both CTRL+another key or SHIFT+another key. If you have any ideas that would...
2
5712
by: petedawn | last post by:
guys, i want to capture all the function key presses from F1 to F12. now i want that when the user presses F1 from within the browser i should display a alert window saying that they have pressed F1 instead of displaying the browser help. how can i implement this. thanks.
1
3545
by: savithriarul | last post by:
Hi, I am trying to capture the CTRL + c event and then get the selected value and then capture the CTRL + V event and paste the selected value in the selected range in the fp webform 2.5. any pointers to this issue will be of most help.. Thanks in advance
0
10600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9175
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7642
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.