473,775 Members | 2,362 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

KeyPress Question

meh
This should wotk I think but its not trapping the Insert or Delete key???
Do I not have this written correctly?
if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show ("Pressed " + e.KeyCode);
}

}
Nov 16 '05 #1
7 8090
meh wrote:
This should wotk I think but its not trapping the Insert or Delete key???
Do I not have this written correctly?

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show ("Pressed " + e.KeyCode);
}

}


Isn't the following what you're after?

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
Nov 16 '05 #2
Hi meh,

If you read carefully in MSDN there is written

MSDN:
"The KeyPress event is not raised by noncharacter keys; however, the
noncharacter keys do raise the KeyDown and KeyUp events."

Delete and Insert keys are non-character keys.
--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no************ *@cox.net> wrote in message
news:eg******** ******@TK2MSFTN GP10.phx.gbl...
This should wotk I think but its not trapping the Insert or Delete key???
Do I not have this written correctly?
if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show ("Pressed " + e.KeyCode);
}

}

Nov 16 '05 #3
meh
Sorry I forgot...I am using the KeyDown event i.e.

private void treeView1_KeyDo wn(object sender,
System.Windows. Forms.KeyEventA rgs e)
{

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show ("Pressed " + e.KeyCode);
}

}

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl...
Hi meh,

If you read carefully in MSDN there is written

MSDN:
"The KeyPress event is not raised by noncharacter keys; however, the
noncharacter keys do raise the KeyDown and KeyUp events."

Delete and Insert keys are non-character keys.
--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no************ *@cox.net> wrote in message
news:eg******** ******@TK2MSFTN GP10.phx.gbl...
This should wotk I think but its not trapping the Insert or Delete key???
Do I not have this written correctly?
if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show ("Pressed " + e.KeyCode);
}

}


Nov 16 '05 #4
In this case it works with me.
If the problem is that you don't see a message box that says the Ctrl is
pressed that is because the Control is a modifier. Change the followng lines
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
to

if (e.Control)
{
MessageBox.Show ("Pressed " + e.Modifiers);
}

and you'll see the message

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no************ *@cox.net> wrote in message
news:uL******** *****@tk2msftng p13.phx.gbl... Sorry I forgot...I am using the KeyDown event i.e.

private void treeView1_KeyDo wn(object sender,
System.Windows. Forms.KeyEventA rgs e)
{

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show ("Pressed " + e.KeyCode);
}

}

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl...
Hi meh,

If you read carefully in MSDN there is written

MSDN:
"The KeyPress event is not raised by noncharacter keys; however, the
noncharacter keys do raise the KeyDown and KeyUp events."

Delete and Insert keys are non-character keys.
--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no************ *@cox.net> wrote in message
news:eg******** ******@TK2MSFTN GP10.phx.gbl...
This should wotk I think but its not trapping the Insert or Delete key??? Do I not have this written correctly?
if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show ("Pressed " + e.KeyCode);
}

}



Nov 16 '05 #5
meh
The Control key works but
I cant get it to trap the Insert key...

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
{
"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
In this case it works with me.
If the problem is that you don't see a message box that says the Ctrl is
pressed that is because the Control is a modifier. Change the followng
lines
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}


to

if (e.Control)
{
MessageBox.Show ("Pressed " + e.Modifiers);
}

and you'll see the message

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no************ *@cox.net> wrote in message
news:uL******** *****@tk2msftng p13.phx.gbl...
Sorry I forgot...I am using the KeyDown event i.e.

private void treeView1_KeyDo wn(object sender,
System.Windows. Forms.KeyEventA rgs e)
{

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show ("Pressed " + e.KeyCode);
}

}

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl...
> Hi meh,
>
> If you read carefully in MSDN there is written
>
> MSDN:
> "The KeyPress event is not raised by noncharacter keys; however, the
> noncharacter keys do raise the KeyDown and KeyUp events."
>
> Delete and Insert keys are non-character keys.
> --
> HTH
> Stoitcho Goutsev (100) [C# MVP]
>
>
> "meh" <no************ *@cox.net> wrote in message
> news:eg******** ******@TK2MSFTN GP10.phx.gbl...
>> This should wotk I think but its not trapping the Insert or Delete key??? >> Do I not have this written correctly?
>>
>>
>> if (e.KeyCode == Keys.Insert)
>> {
>> MessageBox.Show ("Pressed " + e.KeyCode);
>> if (e.Control)
>> {
>> MessageBox.Show ("Pressed " + e.KeyCode);
>> }
>> else if (e.Shift)
>> {
>> MessageBox.Show ("Pressed " + e.KeyCode);
>> }
>> else
>> {
>> MessageBox.Show ("Pressed " + e.KeyCode);
>> }
>>
>> }
>>
>>
>
>



Nov 16 '05 #6
> The Control key works but
I cant get it to trap the Insert key...

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}

What do you mean?
In the code you posted if you don't trap the insert key you won't see the
message for the Control modifier.

How come it works?
When I test your code I got the message for both Insert and Ctrl. make sure
you trap KeyDown not KeyPress event. Then make sure that the treeview has
the focus. In order to focus the treeview you have to have nodes inserted.
--

Stoitcho Goutsev (100) [C# MVP]
"meh" <no************ *@cox.net> wrote in message
news:ub******** ******@TK2MSFTN GP09.phx.gbl...
"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
In this case it works with me.
If the problem is that you don't see a message box that says the Ctrl is
pressed that is because the Control is a modifier. Change the followng
lines
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}


to

if (e.Control)
{
MessageBox.Show ("Pressed " + e.Modifiers);
}

and you'll see the message

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"meh" <no************ *@cox.net> wrote in message
news:uL******** *****@tk2msftng p13.phx.gbl...
Sorry I forgot...I am using the KeyDown event i.e.

private void treeView1_KeyDo wn(object sender,
System.Windows. Forms.KeyEventA rgs e)
{

if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show ("Pressed " + e.KeyCode);
}

}

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl...
> Hi meh,
>
> If you read carefully in MSDN there is written
>
> MSDN:
> "The KeyPress event is not raised by noncharacter keys; however, the
> noncharacter keys do raise the KeyDown and KeyUp events."
>
> Delete and Insert keys are non-character keys.
> --
> HTH
> Stoitcho Goutsev (100) [C# MVP]
>
>
> "meh" <no************ *@cox.net> wrote in message
> news:eg******** ******@TK2MSFTN GP10.phx.gbl...
>> This should wotk I think but its not trapping the Insert or Delete

key???
>> Do I not have this written correctly?
>>
>>
>> if (e.KeyCode == Keys.Insert)
>> {
>> MessageBox.Show ("Pressed " + e.KeyCode);
>> if (e.Control)
>> {
>> MessageBox.Show ("Pressed " + e.KeyCode);
>> }
>> else if (e.Shift)
>> {
>> MessageBox.Show ("Pressed " + e.KeyCode);
>> }
>> else
>> {
>> MessageBox.Show ("Pressed " + e.KeyCode);
>> }
>>
>> }
>>
>>
>
>



Nov 16 '05 #7
meh
As a follow up....5 hours later.....the reason the Insert and Delete key
were not being trapping was because I had a context menu assigned to the
treeview???

Go figure......

meh
"meh" <no************ *@cox.net> wrote in message
news:eg******** ******@TK2MSFTN GP10.phx.gbl...
This should wotk I think but its not trapping the Insert or Delete key???
Do I not have this written correctly?
if (e.KeyCode == Keys.Insert)
{
MessageBox.Show ("Pressed " + e.KeyCode);
if (e.Control)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else if (e.Shift)
{
MessageBox.Show ("Pressed " + e.KeyCode);
}
else
{
MessageBox.Show ("Pressed " + e.KeyCode);
}

}

Nov 16 '05 #8

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

Similar topics

1
3504
by: dave | last post by:
I've designed a nice little App that works something like a spreadsheet using the MSHFlexgrid control. Many users are inclined to press the tab key, expecting the program to respond like excel would but it doesn't. It simply leaves the MSHFlexgrid ang they loose the data they were entering in the particular cell. Is there some way I can receive the tab keypress in some event processing routine so I can respond as I do with a return...
4
8988
by: phil_gg04 | last post by:
Dear Javascript Experts, I'm currently implementing Anyterm, a terminal emulator on a web page. It consists of an Apache module, some XmlHTTP and a bit of Javascript. The idea is to give you shell access to your server from (almost) anywhere; other solutions to the problem tend to require access to ports other than 80 and Java. The very primitive first attempt is at http://chezphil.org/anyterm/. A more functional version will be...
1
6195
by: Darren Coleman | last post by:
I need help with 2 keyboard/input questions 1. How do i caputre all keypress events for my application/form? 2. How do I determine which keyboard sent the keypress? What i'm doing is using a USB Barcode scanner, windows sees the scanner as a keyboard. When the scanner reads a barcode it decodes the barcode and sends in the decoded values in as keypresses from a keyboard. I want to be able to tell the diffrence between a keypress from a...
3
3072
by: Terry Olsen | last post by:
Is there anyway to cause a KeyPress event in a datagrid cell? The only way I get a keypress event is if none of the cells are selected. I was hoping to have the program respond to a certain keypress while in a cell of a datagrid but it doesn't fire the keypress event.
3
1874
by: Just Me | last post by:
I noticed that I don't get KeyDown nor KetPress events if NumLock is not on. I can probably find a workaround but it would be nice to know what the rules are. Can anyone tell me when KeyPress event is raised and when it isn't. Thanks
3
7278
by: Nikolay Evseev | last post by:
Hi, I am trying to trace down the Enter key in my Form.KeyPress event handler. The KeyPreview property is set to false, so I'd assume that all key presses should go through my form's KeyPress event handler, right? Ok. If the focus is set to any other control than a button, then the above event handler fires, but if the focus is on a button, then I've no way to know that the Enter key has been pressed or not, because in that case pressing...
2
8002
by: Bob | last post by:
In that event, how can you find out if the keypress event was in a certain column? Say you have datagridview1, columnname1, columnName2 You want to do something only with the keypress event of column2, do nothing special with column1 Private Sub Datagrid1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Datagrid1.KeyPress If Me.datagrid1......... Then - how do you specify its for...
5
3082
by: Henry Jones | last post by:
I am new to C# and wanted to capture the KeyPress for a textbox. I created some code as follows: private void textBox3_KeyPress(object sender, System.EventArgs e) { this.textBox2.Text = sender.ToString();
4
2802
by: Jeff | last post by:
....still new at this. ...hopefully a simple question Is there some practical way of altering the function of a keypress in Visual Web.net 2005 using VB without causing a postback on each keypress? For example: A have a listbox with a number of selections. The up and down keyboard keys change the indicated listbox selection and by default the <tabkey takes the focus away from the listbox and onto a button that will submit the selection. I'm...
2
19297
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I have created for this purpose is derived from class UserControl.
0
9621
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10267
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
10106
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...
1
10046
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8939
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
7463
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
6717
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
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
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.