The key object used in WPF differs from the keys in WinForm, where the key enumeration object differs from the physical key in that it has a function key and cannot be cast as a type. When using the win API to register a hot key, you need to convert it to a Win32 key value, you can use Keyinterop.virtualkeyfromkey (), and the keys can save the combo keys, key is just a single button. There is a Modifiers in the keys, from which you can see that the 0~15 bit is used to store the function keys. The difference between the two graphs can be visually identified by comparing them.
Example code:
Using System.windows.input;namespace demo. Controls{class HotKeyTextBox:BeiLiNu.Ui.Controls.WPF.Controls.XTextBox {private System.Windows.Forms.Keys Pressedkeys = System.Windows.Forms.Keys.None; protected override void Onpreviewkeydown (System.Windows.Input.KeyEventArgs e) {int keyValue = Keyintero P.virtualkeyfromkey (E.key); if ((Keyboard.modifiers & modifierkeys.control) = = Modifierkeys.control) {keyValue + = (int) System.Windows.Forms.Keys.Control; } if ((Keyboard.modifiers & modifierkeys.alt) = = Modifierkeys.alt) {KeyValue + = (int) System.Windows.Forms.Keys.Alt; } if ((Keyboard.modifiers & modifierkeys.shift) = = Modifierkeys.shift) {KeyValue + = (int) System.Windows.Forms.Keys.Shift; } this. Keys = (System.Windows.Forms.Keys) keyValue; E.handled = true; Public System.Windows.Forms.Keys Keys {get {return pressedkeys;} set {Pressedkeys = value; SetText (value); }} private void SetText (System.Windows.Forms.Keys Keys) {this. Text = keys. ToString (); } }}