コード例 #1
0
        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);
            }
        }
コード例 #2
0
        private static void TriggerKey(GameControlBridge keyboard, string keyId)
        {
            var button = new Button()
            {
                Primary = new Button.ButtonBinding()
                {
                    Device = "Keyboard", Key = keyId
                }
            };

            keyboard.ActivateKeyCombination(button);
        }