public void StartDetectPtt(DetectPttCallback callback)
        {
            _detectPtt = true;
            //detect the state of all current buttons
            var pttInputThread = new Thread(() =>
            {
                while (_detectPtt)
                {
                    var bindStates = GenerateBindStateList();

                    for (var i = 0; i < bindStates.Count; i++)
                    {
                        //contains main binding and optional modifier binding + states of each
                        var bindState = bindStates[i];

                        bindState.MainDeviceState = GetButtonState(bindState.MainDevice);

                        if (bindState.ModifierDevice != null)
                        {
                            bindState.ModifierState = GetButtonState(bindState.ModifierDevice);

                            bindState.IsActive = bindState.MainDeviceState && bindState.ModifierState;
                        }
                        else
                        {
                            bindState.IsActive = bindState.MainDeviceState;
                        }

                        //now check this is the best binding and no previous ones are better
                        //Means you can have better binds like PTT  = Space and Radio 1 is Space +1 - holding space +1 will actually trigger radio 1 not PTT
                        if (bindState.IsActive)
                        {
                            for (int j = 0; j < i; j++)
                            {
                                //check previous bindings
                                var previousBind = bindStates[j];

                                if (!previousBind.IsActive)
                                {
                                    continue;
                                }

                                if (previousBind.ModifierDevice == null && bindState.ModifierDevice != null)
                                {
                                    //set previous bind to off if previous bind Main == main or modifier of bindstate
                                    if (previousBind.MainDevice.IsSameBind(bindState.MainDevice))
                                    {
                                        previousBind.IsActive = false;
                                        break;
                                    }
                                    if (previousBind.MainDevice.IsSameBind(bindState.ModifierDevice))
                                    {
                                        previousBind.IsActive = false;
                                        break;
                                    }
                                }
                                else if (previousBind.ModifierDevice != null && bindState.ModifierDevice == null)
                                {
                                    if (previousBind.MainDevice.IsSameBind(bindState.MainDevice))
                                    {
                                        bindState.IsActive = false;
                                        break;
                                    }
                                    if (previousBind.ModifierDevice.IsSameBind(bindState.MainDevice))
                                    {
                                        bindState.IsActive = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    callback(bindStates);
                    //handle overlay

                    foreach (var bindState in bindStates)
                    {
                        if (bindState.IsActive && bindState.MainDevice.InputBind == InputBinding.OverlayToggle)
                        {
                            //run on main
                            Application.Current.Dispatcher.Invoke(
                                () => { _toggleOverlayCallback(false); });
                            break;
                        }
                        else if ((int)bindState.MainDevice.InputBind >= (int)InputBinding.RadioChannel1 &&
                                 (int)bindState.MainDevice.InputBind <= (int)InputBinding.RadioChannelDown)
                        {
                            if (bindState.MainDevice.InputBind == _lastActiveBinding && !bindState.IsActive)
                            {
                                //Assign to a totally different binding to mark as unassign
                                _lastActiveBinding = InputBinding.ModifierIntercom;
                            }

                            //key repeat
                            if (bindState.IsActive && (bindState.MainDevice.InputBind != _lastActiveBinding))
                            {
                                _lastActiveBinding = bindState.MainDevice.InputBind;

                                var IL2PlayerRadioInfo = ClientStateSingleton.Instance.PlayerGameState;

                                if (IL2PlayerRadioInfo != null)
                                {
                                    switch (bindState.MainDevice.InputBind)
                                    {
                                    case InputBinding.RadioChannelUp:

                                        if (!RadioHelper.IsSecondRadioAvailable())
                                        {
                                            RadioHelper.RadioChannelUp(1);
                                        }
                                        else
                                        {
                                            RadioHelper.RadioChannelUp(ClientStateSingleton.Instance.PlayerGameState.selected);
                                        }

                                        break;

                                    case InputBinding.RadioChannelDown:
                                        if (!RadioHelper.IsSecondRadioAvailable())
                                        {
                                            RadioHelper.RadioChannelDown(1);
                                        }
                                        else
                                        {
                                            RadioHelper.RadioChannelDown(ClientStateSingleton.Instance.PlayerGameState.selected);
                                        }
                                        break;

                                    case InputBinding.RadioChannel1:

                                        if (!RadioHelper.IsSecondRadioAvailable())
                                        {
                                            RadioHelper.SelectRadioChannel(1, 1);
                                        }
                                        else
                                        {
                                            RadioHelper.SelectRadioChannel(1, ClientStateSingleton.Instance.PlayerGameState.selected);
                                        }

                                        break;

                                    case InputBinding.RadioChannel2:
                                        if (!RadioHelper.IsSecondRadioAvailable())
                                        {
                                            RadioHelper.SelectRadioChannel(2, 1);
                                        }
                                        else
                                        {
                                            RadioHelper.SelectRadioChannel(2, ClientStateSingleton.Instance.PlayerGameState.selected);
                                        }
                                        break;

                                    case InputBinding.RadioChannel3:
                                        if (!RadioHelper.IsSecondRadioAvailable())
                                        {
                                            RadioHelper.SelectRadioChannel(3, 1);
                                        }
                                        else
                                        {
                                            RadioHelper.SelectRadioChannel(3, ClientStateSingleton.Instance.PlayerGameState.selected);
                                        }
                                        break;

                                    case InputBinding.RadioChannel4:
                                        if (!RadioHelper.IsSecondRadioAvailable())
                                        {
                                            RadioHelper.SelectRadioChannel(4, 1);
                                        }
                                        else
                                        {
                                            RadioHelper.SelectRadioChannel(4, ClientStateSingleton.Instance.PlayerGameState.selected);
                                        }
                                        break;

                                    case InputBinding.RadioChannel5:
                                        if (!RadioHelper.IsSecondRadioAvailable())
                                        {
                                            RadioHelper.SelectRadioChannel(5, 1);
                                        }
                                        else
                                        {
                                            RadioHelper.SelectRadioChannel(5, ClientStateSingleton.Instance.PlayerGameState.selected);
                                        }
                                        break;

                                    case InputBinding.PreviousRadio:
                                        RadioHelper.PreviousRadio();
                                        break;

                                    case InputBinding.NextRadio:
                                        RadioHelper.NextRadio();
                                        break;

                                    case InputBinding.ReadStatus:
                                        RadioHelper.ReadStatus();
                                        break;

                                    default:
                                        break;
                                    }
                                }

                                break;
                            }
                        }
                    }

                    Thread.Sleep(40);
                }
            });

            pttInputThread.Start();
        }
        public void StartDetectPtt(DetectPttCallback callback)
        {
            _detectPtt = true;
            //detect the state of all current buttons
            var pttInputThread = new Thread(() =>
            {
                while (_detectPtt)
                {
                    var bindStates = GenerateBindStateList();


                    for (var i = 0; i < bindStates.Count; i++)
                    {
                        //contains main binding and optional modifier binding + states of each
                        var bindState = bindStates[i];

                        bindState.MainDeviceState = GetButtonState(bindState.MainDevice);

                        if (bindState.ModifierDevice != null)
                        {
                            bindState.ModifierState = GetButtonState(bindState.ModifierDevice);

                            bindState.IsActive = bindState.MainDeviceState && bindState.ModifierState;
                        }
                        else
                        {
                            bindState.IsActive = bindState.MainDeviceState;
                        }

                        //now check this is the best binding and no previous ones are better
                        //Means you can have better binds like PTT  = Space and Radio 1 is Space +1 - holding space +1 will actually trigger radio 1 not PTT
                        if (bindState.IsActive)
                        {
                            for (int j = 0; j < i; j++)
                            {
                                //check previous bindings
                                var previousBind = bindStates[j];

                                if (previousBind.IsActive)
                                {
                                    if (previousBind.ModifierDevice == null && bindState.ModifierDevice != null)
                                    {
                                        //set previous bind to off if previous bind Main == main or modifier of bindstate
                                        if (previousBind.MainDevice.IsSameBind(bindState.MainDevice))
                                        {
                                            previousBind.IsActive = false;
                                            break;
                                        }
                                        if (previousBind.MainDevice.IsSameBind(bindState.ModifierDevice))
                                        {
                                            previousBind.IsActive = false;
                                            break;
                                        }
                                    }
                                    else if (previousBind.ModifierDevice != null && bindState.ModifierDevice == null)
                                    {
                                        if (previousBind.MainDevice.IsSameBind(bindState.MainDevice))
                                        {
                                            bindState.IsActive = false;
                                            break;
                                        }
                                        if (previousBind.ModifierDevice.IsSameBind(bindState.MainDevice))
                                        {
                                            bindState.IsActive = false;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    callback(bindStates);
                    //handle overlay

                    foreach (var bindState in bindStates)
                    {
                        if (bindState.IsActive && bindState.MainDevice.InputBind == InputBinding.OverlayToggle)
                        {
                            //run on main
                            Application.Current.Dispatcher.Invoke(
                                () => { _toggleOverlayCallback(false); });
                            break;
                        }
                        else if ((int)bindState.MainDevice.InputBind >= (int)InputBinding.Up100 &&
                                 (int)bindState.MainDevice.InputBind <= (int)InputBinding.RadioChannelDown)
                        {
                            if (bindState.MainDevice.InputBind == _lastActiveBinding && !bindState.IsActive)
                            {
                                //Assign to a totally different binding to mark as unassign
                                _lastActiveBinding = InputBinding.ModifierIntercom;
                            }

                            //key repeat
                            if (bindState.IsActive && (bindState.MainDevice.InputBind != _lastActiveBinding))
                            {
                                _lastActiveBinding = bindState.MainDevice.InputBind;

                                var dcsPlayerRadioInfo = ClientStateSingleton.Instance.DcsPlayerRadioInfo;

                                if (dcsPlayerRadioInfo != null && dcsPlayerRadioInfo.IsCurrent())
                                {
                                    switch (bindState.MainDevice.InputBind)
                                    {
                                    case InputBinding.Up100:
                                        RadioHelper.UpdateRadioFrequency(100, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Up10:
                                        RadioHelper.UpdateRadioFrequency(10, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Up1:
                                        RadioHelper.UpdateRadioFrequency(1, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Up01:
                                        RadioHelper.UpdateRadioFrequency(0.1, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Up001:
                                        RadioHelper.UpdateRadioFrequency(0.01, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Up0001:
                                        RadioHelper.UpdateRadioFrequency(0.001, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down100:
                                        RadioHelper.UpdateRadioFrequency(-100, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down10:
                                        RadioHelper.UpdateRadioFrequency(-10, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down1:
                                        RadioHelper.UpdateRadioFrequency(-1, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down01:
                                        RadioHelper.UpdateRadioFrequency(-0.1, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down001:
                                        RadioHelper.UpdateRadioFrequency(-0.01, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.Down0001:
                                        RadioHelper.UpdateRadioFrequency(-0.001, dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.ToggleGuard:
                                        RadioHelper.ToggleGuard(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.ToggleEncryption:
                                        RadioHelper.ToggleEncryption(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.NextRadio:
                                        RadioHelper.SelectNextRadio();
                                        break;

                                    case InputBinding.PreviousRadio:
                                        RadioHelper.SelectPreviousRadio();
                                        break;

                                    case InputBinding.EncryptionKeyIncrease:
                                        RadioHelper.IncreaseEncryptionKey(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.EncryptionKeyDecrease:
                                        RadioHelper.DecreaseEncryptionKey(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.RadioChannelUp:
                                        RadioHelper.RadioChannelUp(dcsPlayerRadioInfo.selected);
                                        break;

                                    case InputBinding.RadioChannelDown:
                                        RadioHelper.RadioChannelDown(dcsPlayerRadioInfo.selected);
                                        break;


                                    default:
                                        break;
                                    }
                                }


                                break;
                            }
                        }
                    }

                    Thread.Sleep(40);
                }
            });

            pttInputThread.Start();
        }
        public void StartDetectPtt(DetectPttCallback callback)
        {
            _detectPtt = true;
            var bindingsCount = Enum.GetValues(typeof(InputBinding)).Length;
            //detect the state of all current buttons
            var pttInputThread = new Thread(() =>
            {
                while (_detectPtt)
                {
                    var buttonStates = new bool[bindingsCount];
                    for (var i = 0; i < bindingsCount; i++)
                    {
                        //init to true so the modifier bindings logic is easier
                        buttonStates[i] = true;
                    }

                    var noDevices = true;
                    for (var j = 0; j < InputConfig.InputDevices.Length; j++)
                    {
                        var device = InputConfig.InputDevices[j];

                        if (device != null)
                        {
                            noDevices = false;
                            for (var i = 0; i < _inputDevices.Count; i++)
                            {
                                if (_inputDevices[i].Information.InstanceGuid.Equals(device.InstanceGuid))
                                {
                                    if (_inputDevices[i] is Joystick)
                                    {
                                        _inputDevices[i].Poll();
                                        var state = (_inputDevices[i] as Joystick).GetCurrentState();

                                        if (device.Button >= 128) //its a POV!
                                        {
                                            var pov = state.PointOfViewControllers;
                                            buttonStates[(int)device.InputBind] = pov[device.Button - 128] ==
                                                                                  device.ButtonValue;
                                        }
                                        else
                                        {
                                            buttonStates[(int)device.InputBind] = state.Buttons[device.Button];
                                        }


                                        break;
                                    }
                                    if (_inputDevices[i] is Keyboard)
                                    {
                                        var keyboard = _inputDevices[i] as Keyboard;
                                        keyboard.Poll();
                                        var state = keyboard.GetCurrentState();
                                        buttonStates[(int)device.InputBind] =
                                            state.IsPressed(state.AllKeys[device.Button]);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (j < 4 || j == 8 || j == 10) //==8 is for OverlayToggle == 10 is for intercom
                            {
                                // set to false as its its a main button, not a modifier
                                buttonStates[j] = false;
                            }
                        }
                    }
                    //if no buttons are bound then  call callback with false for everything
                    if (noDevices)
                    {
                        callback(new bool[bindingsCount]);
                    }
                    else
                    {
                        callback(buttonStates);
                        //handle overlay
                        if (buttonStates[(int)InputBinding.OverlayToggle] &&
                            buttonStates[(int)InputBinding.ModifierOverlayToggle])
                        {
                            //run on main
                            Application.Current.Dispatcher.Invoke(
                                () => { _toggleOverlayCallback(false); });
                        }
                    }

                    Thread.Sleep(1);
                }
            });

            pttInputThread.Start();
        }