Questions tagged [keyeventargs]

A KeyEvent is an event that is triggered when a Key is pressed on a keyboard input device. The KeyEventArgs contain information relating to the particular key that was pressed, how long the key was pressed for, and whether any modifier keys were also pressed (such as Ctrl or Alt).

44 questions
16
votes
4 answers

Can I determine if a KeyEventArg is an letter or number?

Is there a way to determine if a key is letter/number (A-Z,0-9) in the KeyEventArgs? Or do I have to make it myself? I found a way with e.KeyCode, is that accurate? if(((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z ) || (e.KeyCode >= Keys.D0 …
Andr
  • 617
  • 2
  • 9
  • 24
15
votes
7 answers

How to get pressed char from System.Windows.Input.KeyEventArgs?

I have System.Windows.Input.KeyEventArgs e variable. I want to get real char. For example, i press } button on keyboard. And normally it returns string like oem.. but i want to get } char. How to do ? [EDIT] I use this in TextBox .
Javidan
  • 566
  • 1
  • 9
  • 25
14
votes
3 answers

KeyEventArgs.Key to char

Is there any way to convert WPF's KeyEventArgs.Key to Char? I tried to use KeyInterop: var x = (Char)KeyInterop.VirtualKeyFromKey(e.Key); For numbers and letters it works fine, but for other characters it doesn't. E.g. for OemComma it returns '1/4'…
max_hassen
  • 387
  • 1
  • 5
  • 16
13
votes
4 answers

Stop the Bell on CTRL-A (WinForms)

Any ideas how to stop the system bell from sounding when CTRL-A is used to select text in a Winforms application? Here's the problem. Create a Winforms project. Place a text box on the form and add the following event handler on the form to allow…
Blue Waters
  • 725
  • 1
  • 4
  • 17
11
votes
5 answers

Convert a System.Windows.Input.KeyEventArgs key to a char

I need to get the event args as a char, but when I try casting the Key enum I get completely different letters and symbols than what was passed in. How do you properly convert the Key to a char? This is what I've tried ObserveKeyStroke(this, new…
Brandon
  • 68,708
  • 30
  • 194
  • 223
11
votes
1 answer

KeyEventArgs.KeyData, KeyEventArgs.KeyCode and KeyEventArgs.KeyValue

I have question about the KeyEventArgs's KeyCode and KeyData and KeyValue. KeyCode and Keydata are Keys type, but I don't know what the difference between them is. For KeyValue, I don't know what it is -- it has an int type, does it return the char…
Bosak
  • 2,103
  • 4
  • 24
  • 43
7
votes
2 answers

Are some keyboards more loquacious than others?

The lead developer says that when he uses my app, his keyboard beeps when he moves between TextBoxes on the TableLayoutPanel via the directional arrow keys. However, I hear no such aural activity. Here's my code: // Had to intercept Up and Down…
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
6
votes
2 answers

How to forbid backspace key in WPF

How can I forbid the Backspace-Key as easy as possible in a WPF-Application? The KeyDown-Event don't catch at the DEL and the Backspace-Key. Thank you!
Ueli
  • 2,301
  • 5
  • 25
  • 29
4
votes
3 answers

C#: Getting the correct keys pressed from KeyEventArgs' KeyData

I am trapping a KeyDown event and I need to be able to check whether the current keys pressed down are : Ctrl + Shift + M ? I know I need to use the e.KeyData from the KeyEventArgs, the Keys enum and something with Enum Flags and bits but I'm not…
Andreas Grech
  • 105,982
  • 98
  • 297
  • 360
4
votes
1 answer

Simulate the Backspace on a button press in WPF\C#

I've written a WPF touchscreen application. Within this application I've written a user control which is a touch screen keyboard. I have all the keys working apart from the backspace. Obviously all the keys are buttons and on the backspace button…
Sun
  • 4,458
  • 14
  • 66
  • 108
4
votes
2 answers

What is causing a system beep?

This is what I'm using to allow the enter button to start the search. It works but causes a system beep. I have no idea why. private void searchbox_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { …
marcmiller2007
  • 119
  • 2
  • 10
3
votes
1 answer

C# KeyEventArgs has wrong KeyCode and KeyData values

I registered a handler for the KeyDown event of my Windows Forms form. I want to react to pressing of Ctrl and +. Here I mean the + key which is not in the calculator part of the keyboard. While debugging I saw that if I press only this key, the…
user3570134
  • 109
  • 8
3
votes
0 answers

Why does KeyEventArgs.KeyCode show a set of incorrect keys when debugging?

When processing a KeyDown event for the Delete key, the KeyCode shows up as RButton | MButton | Back | Space I can determine from the Keys enum that RButton = 2 MButton = 4 Back = 8 Space = 32 Delete = 46 and 2 + 4 + 8 + 32 = 46 But why is…
Rachel
  • 130,264
  • 66
  • 304
  • 490
3
votes
5 answers

break button_click event when enter pressed

Is an easy way to cancel click event when user hit enter on button (instead of mouse click on button?) i have tried with: private void button3_Click(object sender, EventArgs e) { KeyEventArgs ke = e as KeyEventArgs; if (ke !=…
iskrzycki
  • 154
  • 2
  • 13
2
votes
2 answers

Receiving and reading out KeyEventArgs event on a class other than a Form

I'm currently working on a little game as a WinForms project. The gamefield is build out of a grid of Tiles a Player (a separate class) can move on. I want the player to move with the arrow keys and have set up an event handler for it, but it…
Sander Koldenhof
  • 1,223
  • 4
  • 13
  • 26
1
2 3