public void TriggerKeyCombination_AllKeyCodes_GeneratedFileConsistent() { var fileName = Path.GetTempFileName(); var config = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { ["ActiveWindowTitle"] = $"{Path.GetFileName(fileName)} - Notepad" }) .Build(); var mapper = new BindingMapper(new BindingSet()); var controls = new GameControlBridge(config, mapper, new NativeKeyboardSimulator(), new NullMouseSimulator()); using (var process = Process.Start("notepad.exe", fileName)) { foreach (var keyId in new[] { "Key_A", "Key_B", "Key_Home" }) { TriggerKey(controls, keyId); } process.WaitForExit(); File.Delete(fileName); } }
public void KeyBindingListForKeyboardAndMouse() { var bindings = DeserializeSampleBindingFile(DefaultBindingsFilename); Assert.NotNull(bindings); var bindingMapper = new BindingMapper(bindings); var foundBindings = bindingMapper.GetBoundButtons("Keyboard", "Mouse"); Assert.Equal(134, foundBindings.Count); }
public DynamicBindingMapper(IConfiguration config) { var folder = config["BindingsFolder"]; // Watch for any new binding files coming in or being changed _allBindingFileWatcher = new CustomFileWatcher(folder, "*.binds"); // When they do, make sure we've read and parsed the file and add it to our list. // This lets us switch as soon as the value in StartPreset.start changes, without // having to scan all the files again to find the one with that name. _allBindingSubscription = _allBindingFileWatcher.CreatedFiles .Merge(_allBindingFileWatcher.ChangedFiles) .Subscribe(x => { // Load the .binds file var updatedBinding = BindingMapper.FromFile(Path.Combine(folder, x)); var presetName = updatedBinding.GetPresetName(); _allBindingsByPresetName[presetName] = updatedBinding; // If we've seen a change in the current selected preset, then refresh everyone if (string.Equals(presetName, _currentSelectedPresetName)) { BindingsChanged?.Invoke(this, EventArgs.Empty); } }); // Now start raising file events _allBindingFileWatcher.Start(); // Watch for a new preset being selected _selectedBindingFileWatcher = new CustomFileWatcher(folder, "StartPreset.start"); // When it does, switch to that binding set, and notify clients _selectedBindingSubscription = _selectedBindingFileWatcher.CreatedFiles .Merge(_selectedBindingFileWatcher.ChangedFiles) // FileWatcher can still produce multiple notifications for the same thing. For that matter, // users may flick through a few selection before setting. Throttle the updates. .Throttle(TimeSpan.FromSeconds(3)) .Subscribe(x => { Log.Info("Checking for new binding preset"); _currentSelectedPresetName = ReadStartPreset(Path.Combine(folder, x)); Log.Info($"Selecting binding preset {_currentSelectedPresetName}"); // Refresh everyone's list of available bindings BindingsChanged?.Invoke(this, EventArgs.Empty); }); // Now start raising file events _selectedBindingFileWatcher.Start(); }