简体   繁体   English

e.keyChar不适用于Ctrl

[英]e.keyChar does not work for Ctrl

This code shows hashcodes of pressed button, but when i press on Control button i does not do anything. 这段代码显示了按下按钮的哈希码,但是当我按下“控制”按钮时,我什么也没做。 Can help me someone? 能帮我一个人吗?

 private void treeView1_KeyPress(object sender, KeyPressEventArgs e)
    {
       MessageBox.Show(e.KeyChar.GetHashCode().ToString());
    }

C# WinForms C#WinForms

Ctrl is a modifier key, so it doesn't generate keypress events in its own right. Ctrl是修饰键,因此它不会自行生成按键事件。

Think of a keypress as an actual character that has been typed (eg "A"). 将按键视为已键入的实际字符(例如“ A”)。 In contrast, the modifier keys (Ctrl, Alt and Shift) don't usually "type" anything, they tend to work in conjunction with other keys to modifiy their effect (eg shift changes an "a" int an "A"; ctrl often changes "a" into the hotkey for "Select All", Alt may try to open the main menu (if any) that starts with the letter "A") 相反,修饰键(Ctrl,Alt和Shift)通常不“键入”任何内容,它们倾向于与其他键配合使用以修改其效果(例如,Shift会将“ a”转换为“ A”;按ctrl通常会将“ a”更改为“全选”的热键,Alt可能会尝试打开以字母“ A”开头的主菜单(如果有))

To use ctrl you would usually either check its state at the point where a normal key is pressed (eg when "A" is pressed, to determine whether the keypress means "A" or "ctrl+A"), or you might check the key state asynchronously (eg while dragging, checking if ctrl is held down to apply a modification to the drag such as constraining it to drag only in one axis, or to copy the files being dragged rather than moving them) 要使用ctrl,通常可以在按下普通键的位置检查其状态(例如,按下“ A”时,确定按键的意思是“ A”还是“ ctrl + A”),或者您可以检查异步设置关键点状态(例如,在拖动时,检查是否按住ctrl以对拖动进行修改,例如限制其仅在一个轴上拖动,或者复制被拖动的文件而不移动它们)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM