C# Keys Enumeration Confused: Keys.Alt or Keys.RButton | Keys.ShiftKey | Keys.Alt

c#, enums

Solution

If you want to test whether `Alt` is part of the pressed keys, you can perform a bitwise test;

if((keyData & Keys.Alt) == Keys.Alt) {...}

Problem

I was trying to test whether the Alt key was pressed. I had a check similar to: ``` private void ProcessCmdKey(Keys keyData) { if (keyData == Keys.Alt) { System.Console.WriteLine ("Alt Key Pressed"); } } ``` Anyways needless to say when I breakpointed when I had pressed the Alt key the debugger told me the key that was pressed was actually Keys.RButton | Keys.ShiftKey | Keys.Alt Can anyone shed some light on what is going on or perhaps point me to an article that can explain? Thanks FZ Edit: I am still a bit lost as to why the ENUM would have have other bit values set and not simply the Alt key? I understand that the enum can include more than 1 state with the flags attrivbute but I am not sure why it does if all I pressed was Alt?

Original source

Related problems