A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Getting input from keyboardGetting the current pressed key on the keyboard, key combinations, key value and combining mouse clicks with key pressing. |
On Friday, May 28th 2004 at 12:09 PM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 4.3 with 12 votes) |
||
|
When you type on the keyboard the keystrokes go to a particular application, the active application.
If you have further questions feel free to ask them and also check the following pages at MSDN: KeyUp Event KeyPress Event KeyDown Event |
|||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||
|
|||
Current CommentsNice article.
Can you please post tutorial to show "How to Cancel Key Stroke"
For instance, If I want to cancel non Numeric characters being entered in textBox.
Hello,
That's a good addition for this tutorial.
You can cancel they key stroke from the KeyDown event or from the TextChanged event of the TextBox, as in the following example:
Match StrC = Regex.Match(txtC.Text, ("^-+$|^[0-9]+$"));
bool ParseRes = Double.TryParse(txtC.Text, System.Globalization.NumberStyles.Number, System.Globalization.NumberFormatInfo.CurrentInfo, out DblNum);
if (ParseRes == false & txtC.Text != "" & StrC.Success == false)
{
txtC.Text = "";
txtC.Focus();
txtC.BackColor = Color.FromArgb(255, 237, 237);
}
Here I'm using both RegEx and the TryParse() method to check if there is a valid number entered in the TextBox named txtC.
hi, How do i override the keyUp event for my Rich text box, so that it only prints my specified characters and does not print the actual character pressed on the keyboard.
To replace character 'a'
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
//Check if
if (e.KeyChar =='a')
{
e.Handled =true; // This will cancel the keystorke as asked before
textBox1.Text +='\u0634'; //Print unicode char instead of 'a'
}
}
What includes do you have w/ the file
HI ,
My application requies to generate a log file that contains the logs of the keys pressed ,while my application is running .This is irrespective of the active window .For instance if Word is open and keys are pressed i should be able to get the sequence of keys pressed .
Since the events of keys pressed is handle by the acive window I am not able to get the key strokes pressed.
I believe I shall have to capture the key events at the system level.
How do i do this using eVC .
hi,
for VB:
if you dont want the key Up to be processed in your control use the following code
Private Sub textbox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles textbox1.KeyDown
If e.KeyCode = Keys.Up Then
e.SuppressKeyPress = True
End If
end sub
hi if i want to find that which key are pressed in other windows instead of my application form means spying of my computer or any other computer on network than how can i do this
or simply how can i record keyboard inputs and record them in a file all keys for using any application active window and also my program is hiddden so what is the procedure for this.
what if i want to generate and capture the flying window keys' events,thx
hi,
Can i take inputs by pressing two keys at same time, like A+J pressing it simultaneously how do i input to the code.
How about receiving key input into two controls simultaneously? is it possible..? how?
Nice tutorial. But how about getting input from keyboard without the form being active? like a keylogger
nice tutorial.but how about Getting Input From Keyboard when computing a grade in a form of bufferedReader and JOption?
I want to know how to use keypad ... thanks
Hi I want to make a type programma for people who want to learn how to type how kan I make a visual element dat randomly changes a Letter on the keyboard
I want to know how to use Arrow keys Or direction Keys... thanks
Like the tutorial above says :
if (keyEvent.KeyData == Keys.A)<-- (the " A" can be replace by another character when you type Keys. you will get a list from visual studio there you can select all the possibilities)
-->
<-- what to do if condition is true -->
{
MessageBox.Show("'A', and only A, was pressed.");
}
I don't get it. I am making a game, and I would like to use the arrow keys to move my person. I imput this code:
private void EpicQuest_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.W)
{
MessageBox.Show("w");
}
}
just to test it, and It didn't to anything when i pushed 'w'. What happened.
I think to move it though, I will put something like
private void EpicQuest_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
pnlYourGuy.Left ;
}
}
or something. Please help me as why it will not work!
Ohh, I figured it out. I had it under the form's thing, and it is almost impossible to select the form.
Some time ago,I programmed my keyboard to give the accent over a vowel, as in è for French texting.Can you please tell me how to remove this feature?
I am working on a Typing Tutor and the ' character does not appear until the second key stroke...which then shows '' so I have to delete one of the 's.All this is messing up my scores and is very frustrating as I cannot see my progress. The key is next to the 'Enter' key..
Some time ago,I programmed my keyboard to give the accent over a vowel, as in è for French texting.Can you please tell me how to remove this feature?
I am working on a Typing Tutor and the ' character does not appear until the second key stroke...which then shows '' so I have to delete one of the 's.All this is messing up my scores and is very frustrating as I cannot see my progress. The key is next to the 'Enter' key..
What you need to do is check the references you use Using .....
You need the IO reference.
Using System.IO;
hi. I want to use Console.Read() to get input from keyboard but first I want to initialize the variable and that the user can simply hit ENTER to confirm its value or delete it (backspace) to enter a new value.
Similar like editing text in a textbox with initial value but obviously without the visual object
thanks
Console.Read() is to get user Input not to read what keys has been pressed. you can do something like.
string rd;
try{
rd = Console.Read();
// messagebox with rd value.toString()
}catch(exption e){//error if not able to read or something
}
Console.Read() is to get user Input not to read what keys has been pressed. you can do something like.
string rd;
try{
rd = Console.Read();
// messagebox with rd value.toString()
}catch(exption e){//error if not able to read or something
}
@Luciano thanks for your answer. Maybe I should explain better
My goal is to modify individual fields of a record. Once I select the desired one, I need to get from keyboard its new contents and update it but I want to have its previous content as an initial value, so the user can decide to keep it by simply hitting ENTER or edit it to a new value by backspacing and typing
Hope I have explained better this time. Thanks again
Carlos
Hi carlos I hope you don't mean a database record cause if that's so then, what you need todo is learn datasets you kan fill a dataset en retreieve data from a database than you kan edit a value in de recordand from there I don't know if there is a faster way cause i'm not that familiar with C#
at the website csharpstation.com you can learn dataset I think also here cause I find this the best website with tutorials for Csharp.
Dataset are really a mess. I don't like it i'm a php Mysql programmer I also program in Csharp also am I still learning if you want or need help you can always try and ask me I have sample code for datasets how to use them and how they work so If you like to see these codes or prefer a more private contact environment i;ll provide a link tomorrow online wich you only have to fill in your email after you've done that then it would be saved in my mail box and you will receive an email from me automatically with my info. but thats only if you want maybe we can learn from eachother
What to do to read the number of key pressed even the application is minimized or other application is running and that program is running in the background.
You are talking about a keylogger to make one you will need something like a hook you will need to run the program as a process and do the reading.;)
you can also download keyloggers
Related Tutorials
Related Source Code
C# Job Search