1

How can I extract the KeyCode flag (a System.Windows.Forms.Keys value without modifiers) itself from a System.Windows.Forms.Keys value?

Let's say the Keys has the flags Keys.Control, Keys.Shift and Keys.A. I want to extract the Keys.A flag, but the Keys´s flags (including modifiers) are variable.

2 Answers 2

9

The Keys enum already has a mask for that, its name will not surprise you:

 Keys code = keyData & Keys.KeyCode; 

Its underlying value is 0xffff, effectively masking off the modifier state bits. A similar mask value is available to isolate the modifiers bits, its is Keys.Modifiers (0xffff0000).

Sign up to request clarification or add additional context in comments.

Comments

2

I think this is what you want:

Keys excludeModifier = yourKey & ~Keys.Control & ~Keys.Shift & ~Keys.Alt; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.