KeyEventArgs.KeyData,KeyEventArgs.Key code和KeyEventArgs.KeyValueKeyData、KeyEventArgs、Key、KeyValue

2023-09-03 10:16:57 作者:しovの流ジ

我有关于 KeyEventArgs 键code KEYDATA问题 KEYVALUE 键code KEYDATA 是按键式的,但我不知道他们之间的区别是什么。对于 KEYVALUE ,我不知道它是什么 - 它有一个 INT 键入,它返回< code中的pressed键>字符值?

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?

我没有与关键事件很多经验;他们如何运作,以及如何使用它们将大大AP preciated任何解释。

I don't have much experience with Key events; any explanation of how they function and how to use them would be greatly appreciated.

推荐答案

键code 包含的数据所产生的密钥的KeyUp 的KeyDown 事件。 KEYDATA 包含该键的组合加上Ctrl,Shift或Alt键(如果有)这些都是pressed。

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.

例如:

preSS(按住)Ctrl键。 的KeyDown 将提高,键code Keys.ControlKey KEYDATA Keys.ControlKey | Keys.Control 。 在按住CTRL pressed,preSS SHIFT。 的KeyDown 将提高,键code Keys.ShiftKey KEYDATA Keys.ShifKey | Keys.Shift | Keys.Control 。 Press (and hold) CTRL. KeyDown will be raised, KeyCode will be Keys.ControlKey, KeyData will be Keys.ControlKey | Keys.Control. While still holding CTRL pressed, press SHIFT. KeyDown will be raised, KeyCode will be Keys.ShiftKey and KeyData will be Keys.ShifKey | Keys.Shift | Keys.Control.

注意 KEYDATA 键code 可以包含在的 枚举(如 Keys.A Keys.NumPad4 Keys.Up )。请注意,当修改关键之一是pssed,为再由两个值 KEYDATA psented $ P $(一为他们的关键,一个用于修正值$ P $ )。该改性剂也可通过Modifiers属性。

Note that KeyData and KeyCode can contain any value in the Keys enumeration (such as Keys.A, Keys.NumPad4 or Keys.Up). Note that when one of the modifier keys are pressed, it is represented by two values in KeyData (one for they key and one for the modifier value). The modifiers are also available through the Modifiers property.

KEYVALUE 将返回一个数值再presenting的关键,基本上是一个整数,再presenting在键$发现价值C $ç

KeyValue will return a numerical value representing the key, essentially an integer representing the value found in KeyCode.