private void Update() { var engagedToggleKeys = ToggleKey.GetEngagedToggleKeys(); bool hotKeyIsPressed = false; KeyValuePair <KeyCombo, HotkeyFunction> primeSuspect = default; for (int i = 0; i < _hotKeyRegistry.Count; i++) { var currentItem = _hotKeyRegistry[i].Key; if (Input.GetKey(currentItem.MainKey)) { if (currentItem.GetKeyComboDown(engagedToggleKeys)) { // If there is no hotkey detected yet, or if this one requires more toggle keys (Ctrl+Shift+S takes precedence over Ctrl+S) if (hotKeyIsPressed == false || (currentItem.GetToggleKeys().Count > primeSuspect.Key.GetToggleKeys().Count)) { primeSuspect = _hotKeyRegistry[i]; hotKeyIsPressed = true; } } } } if (hotKeyIsPressed) { primeSuspect.Value.Action?.Invoke(); } }
public bool TryRegisterHotkey(string functionName, System.Action action, KeyCombo keyCombo) { // Toss out anything where the main key is a toggle key (not using the system correctly). foreach (var toggleKey in ToggleKey.GetAll()) { if (toggleKey.Keys.Contains(keyCombo.MainKey)) { Game.Log(Logging.Category.SONG_DATA, $"Unable to register hotkey: Main key (Keycode.{keyCombo.MainKey}) is a reserved toggle key.", Logging.Level.LOG_WARNING); return(false); } } if (_hotKeyRegistry.Exists(kvp => kvp.Key.Equals(keyCombo))) { // Keycode already registered. var existingHotkeyRegistryItem = _hotKeyRegistry.Find(kvp => kvp.Key.Equals(keyCombo)); Game.LogFormat(Logging.Category.SONG_DATA, "Unable to register hotkey: This key combo ({0}) is already reserved for the function: \"{1}\".", Logging.Level.LOG_WARNING, existingHotkeyRegistryItem.Key.GetSequenceString(), existingHotkeyRegistryItem.Value.FunctionName); return(false); } else { // Successful registration. var newHotkeyFunction = new HotkeyFunction(functionName, action); _hotKeyRegistry.Add(new KeyValuePair <KeyCombo, HotkeyFunction>(keyCombo, newHotkeyFunction)); } return(true); }
public static void PressKey(ToggleKey keycode) { // All the ToggleKeys are extended. Press once for down, once for up. NativeMethods.keybd_event((byte)keycode, 0x45, NativeMethods.KEYEVENTF_EXTENDEDKEY | 0, UIntPtr.Zero); NativeMethods.keybd_event((byte)keycode, 0x45, NativeMethods.KEYEVENTF_EXTENDEDKEY | NativeMethods.KEYEVENTF_KEYUP, UIntPtr.Zero); }
private static void ReadCfg() { Logger.LogTrivial("Reading settings from config file..."); ToggleKey = mCfgFile.ReadEnum <Keys>(ECfgSections.SETTINGS.ToString(), ESettings.ToggleKey.ToString(), Keys.F8); ToggleKeyModifier = mCfgFile.ReadEnum <Keys>(ECfgSections.SETTINGS.ToString(), ESettings.ToggleKeyModifier.ToString(), Keys.None); PlayAlertSound = mCfgFile.ReadBoolean(ECfgSections.SETTINGS.ToString(), ESettings.PlayAlertSound.ToString(), true); PlayScanSound = mCfgFile.ReadBoolean(ECfgSections.SETTINGS.ToString(), ESettings.PlayScanSound.ToString(), true); AutoDisableOnTrafficStops = mCfgFile.ReadBoolean(ECfgSections.SETTINGS.ToString(), ESettings.AutoDisableOnTrafficStops.ToString(), true); AutoDisableOnPursuits = mCfgFile.ReadBoolean(ECfgSections.SETTINGS.ToString(), ESettings.AutoDisableOnPursuits.ToString(), true); //BetaKey = mCfgFile.ReadString(ECfgSections.SETTINGS.ToString(), ESettings.BetaKey.ToString(), "YourBetaKeyHere"); Logger.LogTrivial("ToggleKey = " + ToggleKey.ToString()); CameraDegreesFOV = mCfgFile.ReadInt32(ECfgSections.CAMERAS.ToString(), ECameras.CameraDegreesFOV.ToString(), cCameraDegreesFOV); CameraRange = (float)mCfgFile.ReadDouble(ECfgSections.CAMERAS.ToString(), ECameras.CameraRange.ToString(), cCameraRange); CameraMinimum = (float)mCfgFile.ReadDouble(ECfgSections.CAMERAS.ToString(), ECameras.CameraMinimum.ToString(), (float)cCameraMinRange); DriverFrontAngle = mCfgFile.ReadInt32(ECfgSections.CAMERAS.ToString(), ECameras.DriverFrontAngle.ToString(), cDriverFrontAngle); DriverRearAngle = mCfgFile.ReadInt32(ECfgSections.CAMERAS.ToString(), ECameras.DriverRearAngle.ToString(), cDriverRearAngle); PassengerRearAngle = mCfgFile.ReadInt32(ECfgSections.CAMERAS.ToString(), ECameras.PassengerRearAngle.ToString(), cPassengerRearAngle); PassengerFrontAngle = mCfgFile.ReadInt32(ECfgSections.CAMERAS.ToString(), ECameras.PassengerFrontAngle.ToString(), cPassengerFrontAngle); VehicleRescanBuffer = mCfgFile.ReadInt32(ECfgSections.CAMERAS.ToString(), ECameras.VehicleRescanBuffer.ToString(), cVehicleRescanBuffer); SecondsBetweenAlerts = mCfgFile.ReadInt32(ECfgSections.ALERTS.ToString(), EAlerts.SecondsBetweenAlerts.ToString(), cSecondsBetweenAlerts); ProbabilityOfAlerts = mCfgFile.ReadInt32(ECfgSections.ALERTS.ToString(), EAlerts.ProbabilityOfAlerts.ToString(), cProbabilityOfAlerts); StolenVehicleWeight = mCfgFile.ReadInt32(ECfgSections.ALERTS.ToString(), EAlerts.StolenVehicleWeight.ToString(), cDefaultStolenVehicleWeight); OwnerWantedWeight = mCfgFile.ReadInt32(ECfgSections.ALERTS.ToString(), EAlerts.OwnerWantedWeight.ToString(), cDefaultOwnerWantedWeight); OwnerLicenseSuspendedWeight = mCfgFile.ReadInt32(ECfgSections.ALERTS.ToString(), EAlerts.OwnerLicenseSuspendedWeight.ToString(), cDefaultOwnerLicenseSuspendedWeight); OwnerLicenseExpiredWeight = mCfgFile.ReadInt32(ECfgSections.ALERTS.ToString(), EAlerts.OwnerLicenseExpiredWeight.ToString(), cDefaultOwnerLicenseExpiredWeight); UnregisteredVehicleWeight = mCfgFile.ReadInt32(ECfgSections.ALERTS.ToString(), EAlerts.UnregisteredVehicleWeight.ToString(), cDefaultUnregisteredVehicleWeight); RegisrationExpiredWeight = mCfgFile.ReadInt32(ECfgSections.ALERTS.ToString(), EAlerts.RegisrationExpiredWeight.ToString(), cDefaultRegisrationExpiredWeight); NoInsuranceWeight = mCfgFile.ReadInt32(ECfgSections.ALERTS.ToString(), EAlerts.NoInsuranceWeight.ToString(), cDefaultNoInsuranceWeight); InsuranceExpiredWeight = mCfgFile.ReadInt32(ECfgSections.ALERTS.ToString(), EAlerts.InsuranceExpiredWeight.ToString(), cDefaultInsuranceExpiredWeight); AdjustAlertWeights(); }
public void LoadData() { //default values m_aToggleKeyData = new List<ToggleKey>(); m_aTarget = new List<int>(); BitConverter.IsLittleEndian = true; List<PropertyReader.Property> props = PropertyReader.getPropList(pcc, pcc.Exports[index].Data); foreach (PropertyReader.Property p in props) { if (pcc.getNameEntry(p.Name) == "m_aTarget") { int count2 = BitConverter.ToInt32(p.raw, 24); for (int k = 0; k < count2; k++) { m_aTarget.Add(BitConverter.ToInt32(p.raw, 28 + k * 4)); } } else if (pcc.getNameEntry(p.Name) == "m_TargetActor") m_TargetActor = p.Value.IntValue; else if (pcc.getNameEntry(p.Name) == "m_aToggleKeyData") { int pos = 28; int count = BitConverter.ToInt32(p.raw, 24); for (int j = 0; j < count; j++) { List<PropertyReader.Property> p2 = PropertyReader.ReadProp(pcc, p.raw, pos); ToggleKey key = new ToggleKey(); for (int i = 0; i < p2.Count(); i++) { if (pcc.getNameEntry(p2[i].Name) == "m_bToggle") key.m_bToggle = p2[i].Value.IntValue != 0; if (pcc.getNameEntry(p2[i].Name) == "m_bEnable") key.m_bEnable = p2[i].Value.IntValue != 0; pos += p2[i].raw.Length; } m_aToggleKeyData.Add(key); } } } }