-2

I have a List<System.Windows.Forms.Keys>. I want to check if all Keys in the list are pressed in a keydown event.

But how?

My method is:

public bool Triggered( string indentifier, KeyEventArgs e )
{
    List<Keys> keys = Shortcuts.Keys.First( x => Shortcuts[x].Indentifier == indentifier );
    keys.Reverse();
    foreach( Keys key in keys )
    {
        if ( e.KeyCode != key )
            return false;
    }

    return true;
}

Getting the keys works but the check don't.

SmoothOS
  • 3
  • 2

1 Answers1

1

Answer to your question Why is e.KeyCode the same key every time but when I do if ( e.KeyCode == Keys.Control && e.KeyCode == Keys.S ) because it is a flag enum (answer for detailed explanation).

you can do is change your code to :

 List<Keys> keys = Shortcuts.Keys.First( x => Shortcuts[x].Indentifier == indentifier );
 keys.Reverse();

 Keys allKey = Keys.None;
 keys.ForEach(ele => allKey |= ele);

 return (e.KeyData == allKey);
Lucifer
  • 1,594
  • 2
  • 18
  • 32