0

I was having a problem with keyboard combinations in VSCode etc. Specifically, I started to see that my ctrl + alt combinations stopped working.

I wrote a c# app to debug the problem and when I press left ctrl + left alt (in that order) I only get left ctrl. When I press left alt + left ctrl (in that order) I get alt + System. What does "system" mean? If it's some application grabbing that key combo, any thoughts on how can I tell whick one?

using System;
using System.Windows;
using System.Windows.Input;

namespace KeyCaptureWPF
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            KeyDown += MainWindow_KeyDown;
        }

        private void MainWindow_KeyDown(object sender, KeyEventArgs e)
        {
            // Check if the ESC key is pressed
            if (e.Key == Key.Escape)
                Close();

            // Output the pressed key(s)
            string keyCombination = GetKeyCombination(e);
            OutputTextBlock.Text = $"Key(s) Pressed: {keyCombination}";
        }

        private string GetKeyCombination(KeyEventArgs e)
        {
            string combination = string.Empty;

            // Check if the key combination includes any modifier keys
            if (Keyboard.Modifiers != ModifierKeys.None)
            {
                if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))
                    combination += "Alt + ";

                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                    combination += "Ctrl + ";

                if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                    combination += "Shift + ";
            }

            // Append the pressed key
            combination += e.Key.ToString();

            return combination;
        }
    }
}

Kollar
  • 11
  • 2
  • `System.Windows.Input.Key.System` is *"A special key masking the real key being processed as a system key."* (from [msdn](https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.key?view=windowsdesktop-7.0)). – Sinatr Jul 06 '23 at 14:38
  • For keyboard-shortcuts In wpf see [this topic](https://stackoverflow.com/q/1361350/1997232). – Sinatr Jul 06 '23 at 14:47

0 Answers0