473,569 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to handle Ctrl+Enter

hi, there is still no answer, i wonder if there is a way to handle the
multiple key-press event on a C# windows form, like "Ctrl+Enter "
Nov 16 '05 #1
3 23237
Use the KeyDown or KeyUp event. The KeyEventArgs passed to the event
has a property "Control" that tells you whether the Ctrl key was
pressed. You can then check KeyValue to see if Enter was pressed (13?).
Alternatively, you can read KeyData to check for both keys at once using
bitwise OR:

if (e.KeyData == (Keys.ControlKe y | Keys.Enter))
Joshua Flanagan
http://flimflan.com/blog

Coder wrote:
hi, there is still no answer, i wonder if there is a way to handle the
multiple key-press event on a C# windows form, like "Ctrl+Enter "

Nov 16 '05 #2
Hi Coder,

You can check for Ctrl inside the KeyPress event by using the static
properties Control.Modifie rKeys
In theory you should be able to do

if(e.KeyChar == (char)13 && Control.Modifie rKeys == Keys.Ctrl)

Except this doesn't work. Modifierkeys are translated to characters
inside the KeyPress event. When you hold ctrl while clicking Enter
(char)10 is sent instead of (char)13 and the Control click is suppressed,
so all you have to do to detect Ctrl+Enter is

if(e.KeyChar == (char)10)

The same goes for other combinations like

if(e.KeyChar == (char)97) // [A]
if(e.KeyChar == (char)1 ) // [CTRL]+[A]

To detect key combinations put something like this inside the KeyPress
event

MessageBox.Show (((int)e.KeyCha r).ToString());

In the end, you might be better off using the KeyUp/KeyDown events as
Joshua said

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
10x a lot !!
Nov 16 '05 #4

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

Similar topics

10
4375
by: Deano | last post by:
I think that just about sums it up. Is there a fix/workaround for this?It's quite annoying behaviour and not user-friendly.thanksMartin
0
1422
by: Coder | last post by:
hi, i am using a c# windows application. i want to handle some keypress events like ctrl+A, shift+enter, etc.. is it easy to handle only one keypress; as KeyPressEventArgs e;... e.KeyPress. best regards..
1
1244
by: Stephen J. Shephard | last post by:
Hi there, I know this is probably a 101-type question, and I've dealt with it using client script blocks before, but I'm curious about what the best way to handle the enter key is.. (i.e., to handle it when it generates a postback). In my particularly frustrating situation, I have a master-detail type datagrid/form page, and when the user...
15
4023
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE CALLING FORM! This is very bad for me, because in my application, Form1 responds to an ENTER keypress by calling Form2. If the user closes Form2 via an...
3
2957
by: yuelinniao | last post by:
hi, I have got a simple way to make "textarea" support "auto-submit" when pressing Ctrl+Enter, and tested under both IE and Firefox. The common old method is like this: <form name=form2> <textarea onkeydown='if(event.keyCode==13 && event.ctrlKey) return document.form2.submit()'> </textarea> </form>
4
8612
by: sravan_reddy001 | last post by:
i had designed a win app(an address book) when the user wants to enter the contact he will type in all the details and "HE SHOULD CLICK ON THE ADDENTRY BUTTON PROVIDED" i want to simplify this task for the user by allowing the data to bw added in database when "HE PRESSED ENTER KEY AFTER ENTERING THE DETAILS"
4
2512
by: BlackMustard | last post by:
hello, i have a userform in a vba macro which contains three text boxes. sometimes i want to fill in only the first one, and other times one or two of the other as well. when i today want to leave a box empty, i have to press one or several times to reach the "submit" command button. is there a way that i could trigger the btnSubmit_Click()...
3
1756
by: mohanty2050 | last post by:
I want to focus another control when I press both Ctrl key and Enter Key in a text box. How can I do this?
0
7695
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
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. ...
0
8119
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...
1
7668
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
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...
1
5509
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...
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.