Skip to content

How to detect multiple keys down on KeyDown event? #5920

Answered by maxkatz6
ShrutiJaiswal1494 asked this question in Q&A
Discussion options

You must be logged in to vote

Your code works fine:

private void DataGrid_KeyDown(object sender, KeyEventArgs e)
{
    Debug.WriteLine($"{e.Key} {e.KeyModifiers}");
    if (e.Key == Key.O && (e.KeyModifiers == KeyModifiers.Control))
    {
        Application.Current.Clipboard.SetTextAsync("xyz");
    }
}

Outputs expected result (Ctrl was pressed first, O was pressed after that with Ctrl kept down):

LeftCtrl Control
O Control

Condition also works and "xyz" is added to the clipboard.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ShrutiJaiswal1494
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants