I am overriding ProcessCmdKey in a control like this:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if ((keyData & Keys.Up) == Keys.Up)
MessageBox.Show("Up arrow");
else if ((keyData & Keys.Right) == Keys.Right)
MessageBox.Show("Right arrow");
// it doesn't matter what I return, the glitch happens anyway
return base.ProcessCmdKey(ref msg, keyData);
}
And when I press the Up arrow key, the message Up arrow appears, but it also appears when I press the Right arrow key. Why is this?
Read the comment above for a description of the problem.
You don’t even need to cast it, because the argument is passed in as a key. So you can compare the two enums just like you would two strings or integers.