简体   繁体   中英

Detecting when 2 (or more) modifier keys are down c# wpf key down event

I'm trying to detect when keys are down/up using this code:

    private void ViewerScreen_KeyUp(object sender, KeyEventArgs e)
    {
        Console.WriteLine($"{e.Key}|UP");
    }

    private void ViewerScreen_KeyDown(object sender, KeyEventArgs e)
    {
        Console.WriteLine($"{e.Key}|DOWN");
    }

However, when I press left alt + left shift (or any other 2 modifier keys at the same time), I just get either alt or shift + system.

How can I print out both alt and shift in that case?

NOTE: if I print e.SystemKey when alt + shift are pressed, then e.SystemKey = None.

Thanks in advance, Lior.

Use

  1. Keyboard.IsKeyDown to find the key held down

  2. e.Key to find the key that was recently pressed

    if (e.Key == Key.LeftAlt && Keyboard.IsKeyDown(Key.LeftShift)) { //--------------------------- }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM