473,573 Members | 4,155 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Capturing key event and remove beep!



I have a tabcontrol where I want to capture the CTRL+C key combination. My
tabcontrol has on its tabpages some treeView controls. My intention is to
intercept the event of pressing the CTRL+C when one of the controls embedded
in the tabControl has the focus. I'm doing this using the KeyDown event.
However, when pressing the CTRL+C my computer sounds a beep - as in 'not
allowed' beep. The capturing of the keycombination works fine, however, the
beep is unacceptable and must be removed.

Previously I've done this by using the KeyPress event and used a "e.Handled
= true;" command to avoid the beep. However, I cannot manage to capture the
CTRL+C key combination (I'm aware of the Controls.KeyMod ifier functionality
but not sure how to construct the clause that keys on the CTRL+C combination).

1) Does Anyone know how to capture the CTRL+C using the KeyPress event.

I've managed to remove the beep and keep program functionality intact using
the following:

private void tabControlTop_K eyPress(object sender, KeyPressEventAr gs e)
{
e.Handled = true;
}

....along with:

private void tabControlTop_K eyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Z && e.Control)..... .ya da ya da

.....however I feel that it is somewhat of a 'hack' using the Handled
property in this way - merely showing my shortsommings in understanding what
generates the beep.

2) Any suggestions to how this should be done.

Best regards Jesper


Aug 11 '07 #1
2 4758
Jesper wrote:
[...]
Previously I've done this by using the KeyPress event and used a "e.Handled
= true;" command to avoid the beep. However, I cannot manage to capture the
CTRL+C key combination (I'm aware of the Controls.KeyMod ifier functionality
but not sure how to construct the clause that keys on the CTRL+C combination).
The Control.Modifie rKeys property is a flags enum, so you can use it
like this:

if (e.KeyChar == 'C' && (((Control)send er).ModifierKey s &
Keys.Control) == Keys.Control)
{
// Ctrl-C was pressed.
}

(The use of "sender" is to ensure that the correct control is used to
get the ModifierKeys property...the sender is the one for which those
flags will be set and relevant, even if you should happen to move the
code to someplace else. Obviously, if you are writing an override to
OnKeyPress rather than handling the KeyPress event, this isn't necessary).

I don't have time at the moment to go back and verify myself, but I'm a
bit surprised that you still get the beep if you set e.Handled in the
KeyDown handler.

That said, it's my preference to handle this sort of thing more
explicitly. By overriding Control.Process DialogKey, you make it clear
that the key is a specific user-command type of key, and avoid having
the key-press getting passed along to other code in the chain of window
message event handling. In particular, the base class implementation
that emits the beep when it sees a key it doesn't know how to deal with. :)

Pete
Aug 11 '07 #2
1) Does Anyone know how to capture the CTRL+C using the KeyPress event.

You will need to cast the KeyChar value to int and then check for the value
0x03 (ASCII Control Code) for Ctrl-C.

I do this all the time with code similar to the following...

private void MainForm_KeyPre ss(object sender, KeyPressEventAr gs e)
{
// suppress some keys to avoid annoying beep
switch((int)e.K eyChar)
{
case 0x03: // Control-C (Copy)
case 0x08: // Backspace
case 0x0d: // Carriage Return
case 0x16: // Control-V (Paste)
case 0x18: // Control-X (Cut)
e.Handled = true;
break;
}
}

hth
--
Gregg Walker
Aug 13 '07 #3

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

Similar topics

3
9419
by: Randi | last post by:
Hi All, I have a problem on a username password login form. I use: txtPassword.Text = StrConv(txtPassword.Text, vbProperCase) to validate the proper case when someone enters their name and password. It work when you use the button to continue, but if you hit enter on your keyboard the event apparently doesnt lose focus and it says you...
3
4956
by: Greg | last post by:
I want to be able to capture the user pressing Ctrl+S. I know that the IE browser has a key binding for Ctrl+S but is there any way that I can be notified of this key press anyway. I have found tons of examples of capturing keys in IE but *none* of them work for capturing Ctrl+S, Ctrl+F, Ctrl+P,etc or any key combination that has a binding...
2
2289
by: Ivo | last post by:
In an Win/IE-only application, some checkboxes and the like have been assigned accesskeys, so pressing alt+w focuses a checkbox, alt+b another. This is very convenient. However, when the checkboxes are hidden, for example because they are in a div styled "display:none", pressing the magic key combination does not work of course, but instead...
5
1529
by: Tim Marshall | last post by:
In an A97 app I'm redeveloping, I've got a field in a table called TS_LAST_PRINT which indicates the last date this record was printed. That is a hard copy was produced, not an on screen print preview. I'm sure I can capture this in code in a proc which does the docmd.printout or a DoCmd.RunCommand acCmdPrint. But what I'm worried about...
2
7016
by: Peter | last post by:
Hello Thanks for reviewing my question. I am trying to consume the Keydown event of the Cntrl-shift-E in a textbox and have noticed that when I press key this combination a beep is made even though the event works correctly? How can I get rid of this beep? I thought that setting the e.Handled to true would do it but no luck private void...
10
6000
by: Andrew | last post by:
Hi, I have a messagebox that pops up due to an event. I did it in javascript. ie. alert("Time's up. Assessment Ended"); I want to capture the OK and Cancel events of this alert messagebox. My code is in C#/ASP.NET. TIA. Andrew.
17
4306
by: Lauren Wilson | last post by:
Does anyone know if it is possible to capture FTP responses to various FTP commands when managing an FTP session from a VBA procedure? For example, if we try to login to an FTP server and the login info is incorrect, FTP replies with a message to that effect. I need to capture those kinds of responses and advise the user of an Access app...
6
4217
by: MLH | last post by:
Using A97. Want to examine 17-char VIN entered by user. VIN codes are alphanumeric and do not contain Oh's to prevent the confusion that could result if zeros were misread as O's or o's. So, if a user types a 17-char VIN into the textbox that has an Oh in it (lower or upper case) - I would like to change it to a zero during the...
16
3576
by: Neil | last post by:
I am using Access 2003, and have an ongoing problem of every once in a while losing an event procedure for a form or control. The procedure's still in the code module, but the form or control's property sheet does not show "". I have to manually put it back, and then everything's fine. Does anyone know what causes this phenomenon, or, at...
0
7789
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
7707
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
8215
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
7800
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
6432
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
5605
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
2227
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1325
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1048
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...

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.