keyeventargs

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

瘦欲@ 提交于 2019-12-05 01:35:33
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 && e.KeyCode <= Keys.D9 ) || (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9)) You can use the char.IsLetterOrDigit() method on the KeyCode of the event args: bool isLetterOrDigit = char.IsLetterOrDigit((char) keyEventArgs.KeyCode); Char.IsNumber() and Char.IsLetter() In WPF? Use PreviewTextInput or TextInput events instead of KeyDown 来源: https

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

半世苍凉 提交于 2019-12-04 08:44:48
问题 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 sure on how to check for the combination. 回答1: You need to use the Modifiers property of the KeyEventArgs class. Something like: //asumming e is of type KeyEventArgs (such as it is // on a KeyDown event handler // .. bool ctrlShiftM; //will be true

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

為{幸葍}努か 提交于 2019-12-03 12:03:33
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 ObervableKeyStrokeEvent((char)((KeyEventArgs)e.StagingItem.Input).Key)); Edit: I also don't have the KeyCode property on the args. I'm getting them from the InputManager.Current.PreNotifyInput event. Wallstreet Programmer See How to convert a character in to equivalent System.Windows.Input.Key Enum value? Use KeyInterop.VirtualKeyFromKey instead.

KeyEventArgs.KeyData, KeyEventArgs.KeyCode and KeyEventArgs.KeyValue

左心房为你撑大大i 提交于 2019-12-03 02:41:20
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 value of the pressed key? I don't have much experience with Key events; any explanation of how they function and how to use them would be greatly appreciated. KeyCode contains data for the key that produced the KeyUp or KeyDown event. KeyData contains the combination of that key together with CTRL, SHIFT or ALT if any of those were pressed.

Stop the Bell on CTRL-A (WinForms)

落爺英雄遲暮 提交于 2019-12-01 14:05:43
问题 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 CTRL - A to select all the text in the textbox (no matter which control has the focus). void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.A && e.Modifiers == Keys.Control) { System.Diagnostics.Debug.WriteLine("Control and A