internal static void PostKeys(ConsoleDispatcher dispatcher, string line, bool appendCarriageReturn = false, TimeSpan timeout = default(TimeSpan)) { IntPtr pKeybLayout = NativeMethods.GetKeyboardLayout(0); foreach (char keyChar in line) { short keyScan = NativeMethods.VkKeyScanEx(keyChar, pKeybLayout); byte virtualKey = (byte)(keyScan & 0x00ff); VsKeyInfo keyInfo = VsKeyInfo.Create( KeyInterop.KeyFromVirtualKey(virtualKey), keyChar, virtualKey); dispatcher.PostKey(keyInfo); } if (appendCarriageReturn) { dispatcher.PostKey(VsKeyInfo.Enter); } // queue a cancel operation to prevent test getting "stuck" if (timeout != TimeSpan.Zero) { var cancelWasQueued = TryQueueCancelWaitKey(dispatcher, timeout); Assert.True(cancelWasQueued); } }
public void SimplePostKeyWaitKey() { var privateWpfConsole = new Mock <IPrivateWpfConsole>(); var dispatcher = new ConsoleDispatcher(privateWpfConsole.Object); var postedKey = VsKeyInfo.Create(Key.Z, 'z', 0); dispatcher.PostKey(postedKey); // test key available Assert.True(dispatcher.IsKeyAvailable); // queue a cancel operation to prevent test getting "stuck" // should the following WaitKey call fail bool cancelWasQueued = InteractiveHelper.TryQueueCancelWaitKey(dispatcher, timeout: TimeSpan.FromSeconds(5)); Assert.True(cancelWasQueued); // blocking VsKeyInfo keyInfo = dispatcher.WaitKey(); Assert.Equal(keyInfo, postedKey); // queue should be empty Assert.False(dispatcher.IsKeyAvailable); }
public void SimplePostKeyWaitKey() { var privateWpfConsole = new Mock<IPrivateWpfConsole>(); var dispatcher = new ConsoleDispatcher(privateWpfConsole.Object); var postedKey = VsKeyInfo.Create(Key.Z, 'z', 0); dispatcher.PostKey(postedKey); // test key available Assert.True(dispatcher.IsKeyAvailable); // queue a cancel operation to prevent test getting "stuck" // should the following WaitKey call fail bool cancelWasQueued = InteractiveHelper.TryQueueCancelWaitKey(dispatcher, timeout: TimeSpan.FromSeconds(5)); Assert.True(cancelWasQueued); // blocking VsKeyInfo keyInfo = dispatcher.WaitKey(); Assert.Equal(keyInfo, postedKey); // queue should be empty Assert.False(dispatcher.IsKeyAvailable); }