Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从值中提取 KeyCode 标志(System.Windows.Forms.Keys没有修饰符的值)本身System.Windows.Forms.Keys?
System.Windows.Forms.Keys
假设有Keys标志Keys.Control和。我想提取标志,但's 标志(包括修饰符)是可变的。Keys.ShiftKeys.AKeys.AKeys
Keys
Keys.Control
Keys.Shift
Keys.A
Keys 枚举已经有一个掩码,它的名字不会让你感到惊讶:
Keys code = keyData & Keys.KeyCode;
它的基础值为 0xffff,有效地屏蔽了修饰符状态位。类似的掩码值可用于隔离修饰符位,它是 Keys.Modifiers (0xffff0000)。
我认为这就是你想要的:
Keys excludeModifier = yourKey & ~Keys.Control & ~Keys.Shift & ~Keys.Alt;