private void ChangeKeyboard(int selectedIndex)
        {
            // can happen eg when using the app, closing, deleting keyboard.json files and restarting
            if (selectedIndex < 0 || selectedIndex > keyboards.Length - 1)
            {
                MessageBox.Show(this, "Invalid keyboard selection. Using the first in the list", "error", MessageBoxButton.OK);
                selectedIndex = 0;
            }

            var result = keyboards[selectedIndex].CreateWpfKeys();

            Keyboard.Children.Clear();
            Keyboard.Children.Add(result.Item1);

            keyPressController.ChangeKeyboard(result.Item2);
            keyPressController.ForceRepaint();

            state.GuiConfiguration.SelectedKeyboardIndex = selectedIndex;
        }
        public MainWindow()
        {
            InitializeComponent();

            Title = $"Keyboord usage v{AppConstants.CurrentVersion} by Kasper B. Graversen";

            var args = new CommandLineParser().ParseCommandLine();

            var style = (Style)FindResource("InformButton");

            configurationRepository = new ConfigurationRepository(new UserStateStandardConfiguraion(args));

            keyboards = configurationRepository.GetKeyboards(style);

            state = configurationRepository.LoadUserState();
            var userState = new DailySessionDecorator(state);
            var counter   = new KeysCounter(userState);

            keyPressController = new KeyPressController(
                () => WindowState == WindowState.Minimized,
                x => CurrentKey.Content       = x,
                x => KeyHistory.Text          = x,
                x => ProductiveRatio.Content  = x.ToString() + "%",
                x => DestructiveRatio.Content = x.ToString() + "%",
                x => NavigationRatio.Content  = x.ToString() + "%",
                x => MetaRatio.Content        = x.ToString() + "%",
                counter,
                null);

            listener = new KeyboardListener(counter, keyPressController);
            listener.Subscribe();

            ResizeWindow(state);

            KeyboardChooser.ItemsSource   = keyboards.Select(x => x.Name);
            KeyboardChooser.SelectedIndex = state.GetGuiConfiguration().SelectedKeyboardIndex;

            keyPressController.ForceRepaint();
        }