///<summary> ///Provides a way for scripts to request user input ... ///</summary> ///<returns></returns> KeyInfo IPSRawConsole.ReadKey(ReadKeyOptions options) { if((options & (ReadKeyOptions.IncludeKeyUp| ReadKeyOptions.IncludeKeyDown)) == 0) { throw new MethodInvocationException("Cannot read key options. To read options either IncludeKeyDown, IncludeKeyUp or both must be set."); } while (true) { if (_inputBuffer.Count == 0) { Dispatcher.BeginInvoke((Action)(() => SetPrompt())); _waitingForKey = true; _gotInputKey.Reset(); _gotInputKey.WaitOne(); _waitingForKey = false; } else { var ki = _inputBuffer.Dequeue(); if (ki.Character != 0) { Dispatcher.BeginInvoke( (Action) (() => ShouldEcho(ki.Character, (options & ReadKeyOptions.NoEcho) == 0))); } if ((((options & ReadKeyOptions.IncludeKeyDown) > 0) && ki.KeyDown) || (((options & ReadKeyOptions.IncludeKeyUp) > 0) && !ki.KeyDown)) { return ki; } } } }
public override KeyInfo ReadKey(ReadKeyOptions options) { if (this.externalRawUI == null) { this.ThrowNotInteractive(); } KeyInfo info = new KeyInfo(); try { info = this.externalRawUI.ReadKey(options); } catch (PipelineStoppedException) { LocalPipeline currentlyRunningPipeline = (LocalPipeline) ((RunspaceBase) this.parentHost.Context.CurrentRunspace).GetCurrentlyRunningPipeline(); if (currentlyRunningPipeline == null) { throw; } currentlyRunningPipeline.Stopper.Stop(); } return info; }
/// <summary> /// Reads the current key pressed in the console. /// </summary> /// <param name="options">Options for reading the current keypress.</param> /// <returns>A KeyInfo struct with details about the current keypress.</returns> public override KeyInfo ReadKey(ReadKeyOptions options) { Logger.Write( LogLevel.Warning, "PSHostRawUserInterface.ReadKey was called"); throw new System.NotImplementedException(); }
public override KeyInfo ReadKey(ReadKeyOptions options) { throw new NotSupportedException(Resources.PSHostRawUserInterfaceReadKeyNotSupported); }
public override KeyInfo ReadKey(ReadKeyOptions options) { return(ConsoleHandler.ReadKey(options)); }
/// <summary> /// This functionality is not currently implemented. The call fails with an exception. /// </summary> /// <param name="options">Unused</param> /// <returns>Nothing</returns> public override KeyInfo ReadKey(ReadKeyOptions options) { throw new NotImplementedException("The method or operation is not implemented."); }
public override KeyInfo ReadKey(ReadKeyOptions options) { var k = Console.ReadKey(); return new KeyInfo() { Character = k.KeyChar}; }
public override KeyInfo ReadKey(ReadKeyOptions options) { return new KeyInfo(); }
public override KeyInfo ReadKey(ReadKeyOptions options) { return(default(KeyInfo)); }
ReadKey(ReadKeyOptions options) { if ((options & (ReadKeyOptions.IncludeKeyDown | ReadKeyOptions.IncludeKeyUp)) == 0) { throw PSTraceSource.NewArgumentException("options", ConsoleHostRawUserInterfaceStrings.InvalidReadKeyOptionsError); } // keyInfo is initialized in the below if-else statement KeyInfo keyInfo; if (cachedKeyEvent.RepeatCount > 0) { // Ctrl-C is not allowed and Ctrl-C is cached. if (((options & ReadKeyOptions.AllowCtrlC) == 0) && cachedKeyEvent.UnicodeChar == (char)3) { // Ctrl-C is in the cache, stop pipeline immediately cachedKeyEvent.RepeatCount--; throw NewPipelineStoppedException(); } // If IncludeKeyUp is not set and cached key events are KeyUp OR // IncludeKeyDown is not set and cached key events are KeyDown, clear the cache if ((((options & ReadKeyOptions.IncludeKeyUp) == 0) && !cachedKeyEvent.KeyDown) || (((options & ReadKeyOptions.IncludeKeyDown) == 0) && cachedKeyEvent.KeyDown)) { cachedKeyEvent.RepeatCount = 0; } } if (cachedKeyEvent.RepeatCount > 0) { KEY_EVENT_RECORDToKeyInfo(cachedKeyEvent, out keyInfo); cachedKeyEvent.RepeatCount--; } else { ConsoleHandle handle = ConsoleControl.GetConioDeviceHandle(); ConsoleControl.INPUT_RECORD[] inputRecords = new ConsoleControl.INPUT_RECORD[1]; ConsoleControl.ConsoleModes originalMode = ConsoleControl.GetMode(handle); // set input mode to exclude mouse or window events // turn off ProcessedInput flag to handle ctrl-c ConsoleControl.ConsoleModes newMode = originalMode & ~ConsoleControl.ConsoleModes.WindowInput & ~ConsoleControl.ConsoleModes.MouseInput & ~ConsoleControl.ConsoleModes.ProcessedInput; try { ConsoleControl.SetMode(handle, newMode); while (true) { int actualNumberOfInput = ConsoleControl.ReadConsoleInput(handle, ref inputRecords); Dbg.Assert(actualNumberOfInput == 1, string.Format(CultureInfo.InvariantCulture, "ReadConsoleInput returns {0} number of input event records", actualNumberOfInput)); if (actualNumberOfInput == 1) { if (((ConsoleControl.InputRecordEventTypes)inputRecords[0].EventType) == ConsoleControl.InputRecordEventTypes.KEY_EVENT) { Dbg.Assert((inputRecords[0].KeyEvent.KeyDown && inputRecords[0].KeyEvent.RepeatCount != 0) || !inputRecords[0].KeyEvent.KeyDown, string.Format(CultureInfo.InvariantCulture, "ReadConsoleInput returns a KeyEvent that is KeyDown and RepeatCount 0")); if (inputRecords[0].KeyEvent.RepeatCount == 0) { // Sometimes Win32 ReadConsoleInput returns a KeyEvent record whose // RepeatCount is zero. This type of record does not // represent a keystroke. continue; } // Ctrl-C is not allowed and Ctrl-C is input if ((options & ReadKeyOptions.AllowCtrlC) == 0 && inputRecords[0].KeyEvent.UnicodeChar == (char)3) { CacheKeyEvent(inputRecords[0].KeyEvent, ref cachedKeyEvent); throw NewPipelineStoppedException(); } // if KeyDown events are wanted and event is KeyDown OR // KeyUp events are wanted and event is KeyUp if ((((options & ReadKeyOptions.IncludeKeyDown) != 0) && inputRecords[0].KeyEvent.KeyDown) || (((options & ReadKeyOptions.IncludeKeyUp) != 0) && !inputRecords[0].KeyEvent.KeyDown)) { CacheKeyEvent(inputRecords[0].KeyEvent, ref cachedKeyEvent); KEY_EVENT_RECORDToKeyInfo(inputRecords[0].KeyEvent, out keyInfo); break; } } } } } finally { ConsoleControl.SetMode(handle, originalMode); } } if ((options & ReadKeyOptions.NoEcho) == 0) { parent.WriteToConsole( keyInfo.Character.ToString(), true); } return keyInfo; }
/// <summary> /// Read key. /// </summary> public override KeyInfo ReadKey(ReadKeyOptions options) { return(_serverMethodExecutor.ExecuteMethod <KeyInfo>(RemoteHostMethodId.ReadKey, new object[] { options })); }
public override KeyInfo ReadKey(ReadKeyOptions options) { throw new NotImplementedException("ReadKey is not implemented. The script is asking for input, which is a problem since there's no console. Make sure the script can execute without prompting the user for input."); }
public abstract KeyInfo ReadKey(ReadKeyOptions options);
public override KeyInfo ReadKey(ReadKeyOptions options) { throw new Exception("Cannot use run commands that require user input"); }
/// <summary> /// Thread method invoked from <see cref="ReadKey"/> that waits for the user to press a key. /// </summary> /// <param name="state"><see cref="Tuple{T1, T2}"/> object containing a <see cref="StreamConnection"/> object and a <see cref="ReadKeyOptions"/> /// object.</param> private void ReadInput(object state) { StreamConnection connection = (state as Tuple <StreamConnection, ReadKeyOptions>).Item1; ReadKeyOptions options = (state as Tuple <StreamConnection, ReadKeyOptions>).Item2; bool inEscapeSequence = false; bool readKey = false; while (!readKey) { if (connection.OutputQueue.Count > 0) { while (connection.OutputQueue.Count > 0) { byte currentByte = connection.OutputQueue.Dequeue(); // Handle the backspace key if (currentByte == 8) { _readKey = new KeyInfo { VirtualKeyCode = 8 }; // If we're not already at the beginning of the line and we're echoing the output, move the cursor left if ((options & ReadKeyOptions.NoEcho) != ReadKeyOptions.NoEcho && CursorPosition.X > 1) { CursorPosition = new Coordinates(CursorPosition.X - 1, CursorPosition.Y); } readKey = true; break; } // The ^X character signifies the start of an ANSI escape sequence else if (currentByte == 27) { inEscapeSequence = true; } // If we're in an escape sequence, read past the "[" and "~" characters else if (currentByte == 91 && inEscapeSequence) { } else if (currentByte == 126 && inEscapeSequence) { } // ^X7 is the home key else if (currentByte == 55 && inEscapeSequence) { _readKey = new KeyInfo { VirtualKeyCode = 0x24 }; // If we're not already at the beginning of the line and we're echoing the output, move the cursor to the start of the line if ((options & ReadKeyOptions.NoEcho) != ReadKeyOptions.NoEcho) { CursorPosition = new Coordinates(1, CursorPosition.Y); } readKey = true; break; } // ^X8 or ^X3 is the end key else if ((currentByte == 56 || currentByte == 51) && inEscapeSequence) { _readKey = new KeyInfo { VirtualKeyCode = 0x23 }; // If we're not already at the beginning of the line and we're echoing the output, move the cursor to the end of the line if ((options & ReadKeyOptions.NoEcho) != ReadKeyOptions.NoEcho) { CursorPosition = new Coordinates(BufferSize.Width, CursorPosition.Y); } readKey = true; break; } // ^XD is the left arrow else if (currentByte == 68 && inEscapeSequence) { _readKey = new KeyInfo { VirtualKeyCode = 0x25 }; // If we're not already at the beginning of the line and we're echoing the output, move the cursor left if ((options & ReadKeyOptions.NoEcho) != ReadKeyOptions.NoEcho && CursorPosition.X > 1) { CursorPosition = new Coordinates(CursorPosition.X - 1, CursorPosition.Y); } readKey = true; break; } // ^XC is the right arrow else if (currentByte == 67 && inEscapeSequence) { _readKey = new KeyInfo { VirtualKeyCode = 0x27 }; // If we're not already at the beginning of the line and we're echoing the output, move the cursor right if ((options & ReadKeyOptions.NoEcho) != ReadKeyOptions.NoEcho && CursorPosition.X < BufferSize.Width) { CursorPosition = new Coordinates(CursorPosition.X + 1, CursorPosition.Y); } readKey = true; break; } // Handle the carriage return sequence else if (currentByte == 13) { _readKey = new KeyInfo { Character = '\r', VirtualKeyCode = 0x0D }; if ((options & ReadKeyOptions.NoEcho) != ReadKeyOptions.NoEcho) { CursorPosition = new Coordinates(1, CursorPosition.Y); } readKey = true; break; } // Otherwise, get the virtual key code and character and populate _readKey else { short virtualKey = User32.VkKeyScan((char)currentByte); int modifiers = virtualKey >> 8; ControlKeyStates controlKeys = 0; if ((modifiers & 2) != 0) { controlKeys |= ControlKeyStates.LeftCtrlPressed; } if ((modifiers & 4) != 0) { controlKeys |= ControlKeyStates.LeftAltPressed; } _readKey = new KeyInfo { Character = (char)currentByte, VirtualKeyCode = (virtualKey & 0xFF), ControlKeyState = controlKeys }; if ((options & ReadKeyOptions.NoEcho) != ReadKeyOptions.NoEcho) { _terminal.TerminalPane.ConnectionTag.Receiver.DataArrived( new byte[] { currentByte }, 0, 1); } readKey = true; break; } } } // If we didn't read a key, sleep for a bit if (!readKey) { Thread.Sleep(50); } } // Signal to ReadKey() that we've read a key _inputSemaphore.Set(); }
public override KeyInfo ReadKey(ReadKeyOptions options) { return(new KeyInfo()); }
/// <summary> /// This functionality is not currently implemented. The call fails with an exception. /// </summary> /// <param name="options">Unused</param> /// <returns>Nothing</returns> public override KeyInfo ReadKey(ReadKeyOptions options) { throw new NotImplementedException("The ReadKey() method is not implemented by MyRawUserInterface."); }
/// <summary> /// This API reads a pressed, released, or pressed and released keystroke /// from the keyboard device, blocking processing until a keystroke is /// typed that matches the specified keystroke options. /// </summary> /// <param name="options">Unused</param> public override KeyInfo ReadKey(ReadKeyOptions options) { ConsoleKeyInfo key = Console.ReadKey(); return new KeyInfo((int)key.Key, key.KeyChar, new ControlKeyStates(), true); }
/// <summary> /// This API reads a pressed, released, or pressed and released keystroke /// from the keyboard device, blocking processing until a keystroke is /// typed that matches the specified keystroke options. In this example /// this functionality is not needed so the method throws a /// NotImplementException exception. /// </summary> /// <param name="options">Options, such as IncludeKeyDown, used when /// reading the keyboard.</param> /// <returns>Throws a NotImplementedException exception.</returns> public override KeyInfo ReadKey(ReadKeyOptions options) { throw new NotImplementedException(); }
/// <summary> /// This API reads a pressed, released, or pressed and released keystroke /// from the keyboard device, blocking processing until a keystroke is /// typed that matches the specified keystroke options. /// </summary> /// <param name="options">Options, such as IncludeKeyDown, used when /// reading the keyboard.</param> /// <returns>Throws a NotImplementedException exception.</returns> public override KeyInfo ReadKey(ReadKeyOptions options) { //throw new NotImplementedException("TODO: Verify my ReadKey code works"); var keyInfo = Console.ReadKey((options & ReadKeyOptions.NoEcho) == ReadKeyOptions.NoEcho); ControlKeyStates ctrlKeyState; switch (keyInfo.Modifiers) { case ConsoleModifiers.Control: ctrlKeyState = ControlKeyStates.LeftCtrlPressed; break; case ConsoleModifiers.Shift: ctrlKeyState = ControlKeyStates.ShiftPressed; break; case ConsoleModifiers.Alt: ctrlKeyState = ControlKeyStates.LeftAltPressed; break; case ConsoleModifiers.Control | ConsoleModifiers.Alt: ctrlKeyState = ControlKeyStates.LeftCtrlPressed | ControlKeyStates.LeftAltPressed; break; case ConsoleModifiers.Control | ConsoleModifiers.Shift: ctrlKeyState = ControlKeyStates.LeftCtrlPressed | ControlKeyStates.ShiftPressed; break; case ConsoleModifiers.Alt | ConsoleModifiers.Shift: ctrlKeyState = ControlKeyStates.LeftAltPressed | ControlKeyStates.ShiftPressed; break; default: ctrlKeyState = 0; break; } return new KeyInfo { Character = keyInfo.KeyChar, ControlKeyState = ctrlKeyState, KeyDown = false, //TODO: Verify this is correct VirtualKeyCode = (int) keyInfo.Key }; }
/// <summary> /// Reads a pressed, released, or pressed and released keystroke /// from the keyboard device, blocking processing until a keystroke /// is typed that matches the specified keystroke options. This /// functionality is not implemented. The call fails with an /// exception. /// </summary> /// <param name="options">A bit mask of the options to be used when /// reading from the keyboard. </param> /// <returns>Throws a NotImplementedException exception.</returns> public override KeyInfo ReadKey(ReadKeyOptions options) { throw new NotImplementedException("The ReadKey() method is not implemented by MyRawUserInterface."); }
/// <summary> /// Read key. /// </summary> public override KeyInfo ReadKey(ReadKeyOptions options) { return _serverMethodExecutor.ExecuteMethod<KeyInfo>(RemoteHostMethodId.ReadKey, new object[] { options }); }
public override KeyInfo ReadKey(ReadKeyOptions options) { throw new NotSupportedException(); }
public override KeyInfo ReadKey(ReadKeyOptions options) { throw new NotImplementedException("Not implemented because not needed"); }
public override KeyInfo ReadKey(ReadKeyOptions options) { // NOTE: readkey options are ignored as they are not really usable or applicable in PM console. VsKeyInfo keyInfo = Console.Dispatcher.WaitKey(); if (keyInfo == null) { // abort current pipeline (ESC pressed) throw new PipelineStoppedException(); } ControlKeyStates states = default(ControlKeyStates); states |= (keyInfo.CapsLockToggled ? ControlKeyStates.CapsLockOn : 0); states |= (keyInfo.NumLockToggled ? ControlKeyStates.NumLockOn : 0); states |= (keyInfo.ShiftPressed ? ControlKeyStates.ShiftPressed : 0); states |= (keyInfo.AltPressed ? ControlKeyStates.LeftAltPressed : 0); // assume LEFT alt states |= (keyInfo.ControlPressed ? ControlKeyStates.LeftCtrlPressed : 0); // assume LEFT ctrl return new KeyInfo(keyInfo.VirtualKey, keyInfo.KeyChar, states, keyDown: (keyInfo.KeyStates == KeyStates.Down)); }
/// <summary> /// This functionality is not currently implemented. The call fails with an exception. /// </summary> /// <param name="options">Unused</param> /// <returns>Nothing</returns> public override KeyInfo ReadKey(ReadKeyOptions options) { return myConsole.ReadKey(options); }
ReadKey(ReadKeyOptions options);
ReadKey(ReadKeyOptions options) { if (_externalRawUI == null) { ThrowNotInteractive(); } KeyInfo result = new KeyInfo(); try { result = _externalRawUI.ReadKey(options); } catch (PipelineStoppedException) { //PipelineStoppedException is thrown by host when it wants //to stop the pipeline. LocalPipeline lpl = (LocalPipeline)((RunspaceBase)_parentHost.Context.CurrentRunspace).GetCurrentlyRunningPipeline(); if (lpl == null) { throw; } lpl.Stopper.Stop(); } return result; }
public override KeyInfo ReadKey(ReadKeyOptions options) { var key = _control.ReadNextKey(); if (0 == (ReadKeyOptions.NoEcho & options)) { _control.Write(key.Character.ToString()); } return key.ToKeyInfo(); }
///<summary> ///Provides a way for scripts to request user input ... ///</summary> ///<returns></returns> public override KeyInfo ReadKey(ReadKeyOptions options) { return _control.ReadKey(options); }
/// <summary> /// This API Reads a pressed, released, or pressed and released keystroke from the keyboard device, blocking processing until a keystroke is typed that /// matches the specified keystroke options. /// </summary> /// <param name="options">Options, such as IncludeKeyDown, used when reading the keyboard.</param> /// <returns>Data for the key that the user pressed.</returns> public override KeyInfo ReadKey(ReadKeyOptions options) { StreamConnection connection = _terminal.TerminalPane.ConnectionTag.Connection as StreamConnection; connection.Capture = true; _inputSemaphore.Reset(); // Start up a thread to watch the terminal's input bufer _inputThread = new Thread(ReadInput) { Name = "PowerShellRawUi Input Thread" }; _inputThread.Start(new Tuple<StreamConnection, ReadKeyOptions>(connection, options)); // ReadInput will signal through this semaphore when a key has been pressed _inputSemaphore.WaitOne(); connection.Capture = false; return _readKey; }
public override KeyInfo ReadKey(ReadKeyOptions options) { throw new NotImplementedException(); }
public override KeyInfo ReadKey(ReadKeyOptions options) { KeyInfo keyInfo; if ((options & (ReadKeyOptions.IncludeKeyDown | ReadKeyOptions.IncludeKeyUp)) != 0) { if (this.cachedKeyEvent.RepeatCount > 0) { if ((options & ReadKeyOptions.AllowCtrlC) != 0 || this.cachedKeyEvent.UnicodeChar != '\u0003') { if ((options & ReadKeyOptions.IncludeKeyUp) == 0 && !this.cachedKeyEvent.KeyDown || (options & ReadKeyOptions.IncludeKeyDown) == 0 && this.cachedKeyEvent.KeyDown) { this.cachedKeyEvent.RepeatCount = 0; } } else { ConsoleControl.KEY_EVENT_RECORD kEYEVENTRECORDPointer = this.cachedKeyEvent; this.cachedKeyEvent.RepeatCount = (ushort)(this.cachedKeyEvent.RepeatCount - 1); throw this.NewPipelineStoppedException(); } } if (this.cachedKeyEvent.RepeatCount <= 0) { SafeFileHandle inputHandle = ConsoleControl.GetInputHandle(); ConsoleControl.INPUT_RECORD[] nPUTRECORDArray = new ConsoleControl.INPUT_RECORD[1]; ConsoleControl.ConsoleModes mode = ConsoleControl.GetMode(inputHandle); ConsoleControl.ConsoleModes consoleMode = mode & (ConsoleControl.ConsoleModes.ProcessedInput | ConsoleControl.ConsoleModes.LineInput | ConsoleControl.ConsoleModes.EchoInput | ConsoleControl.ConsoleModes.MouseInput | ConsoleControl.ConsoleModes.Insert | ConsoleControl.ConsoleModes.QuickEdit | ConsoleControl.ConsoleModes.Extended | ConsoleControl.ConsoleModes.AutoPosition | ConsoleControl.ConsoleModes.ProcessedOutput | ConsoleControl.ConsoleModes.WrapEndOfLine) & (ConsoleControl.ConsoleModes.ProcessedInput | ConsoleControl.ConsoleModes.LineInput | ConsoleControl.ConsoleModes.EchoInput | ConsoleControl.ConsoleModes.WindowInput | ConsoleControl.ConsoleModes.Insert | ConsoleControl.ConsoleModes.QuickEdit | ConsoleControl.ConsoleModes.Extended | ConsoleControl.ConsoleModes.AutoPosition | ConsoleControl.ConsoleModes.ProcessedOutput | ConsoleControl.ConsoleModes.WrapEndOfLine) & (ConsoleControl.ConsoleModes.LineInput | ConsoleControl.ConsoleModes.EchoInput | ConsoleControl.ConsoleModes.WindowInput | ConsoleControl.ConsoleModes.MouseInput | ConsoleControl.ConsoleModes.Insert | ConsoleControl.ConsoleModes.QuickEdit | ConsoleControl.ConsoleModes.Extended | ConsoleControl.ConsoleModes.AutoPosition | ConsoleControl.ConsoleModes.WrapEndOfLine); try { ConsoleControl.SetMode(inputHandle, consoleMode); do { Label0: int num = ConsoleControl.ReadConsoleInput(inputHandle, ref nPUTRECORDArray); if (num == 1 && nPUTRECORDArray[0].EventType == 1 && nPUTRECORDArray[0].KeyEvent.RepeatCount != 0) { if ((options & ReadKeyOptions.AllowCtrlC) != 0 || nPUTRECORDArray[0].KeyEvent.UnicodeChar != '\u0003') { continue; } ConsoleHostRawUserInterface.CacheKeyEvent(nPUTRECORDArray[0].KeyEvent, ref this.cachedKeyEvent); throw this.NewPipelineStoppedException(); } else { goto Label0; } } while (((options & ReadKeyOptions.IncludeKeyDown) == 0 || !nPUTRECORDArray[0].KeyEvent.KeyDown) && ((options & ReadKeyOptions.IncludeKeyUp) == 0 || nPUTRECORDArray[0].KeyEvent.KeyDown)); ConsoleHostRawUserInterface.CacheKeyEvent(nPUTRECORDArray[0].KeyEvent, ref this.cachedKeyEvent); ConsoleHostRawUserInterface.KEY_EVENT_RECORDToKeyInfo(nPUTRECORDArray[0].KeyEvent, out keyInfo); } finally { ConsoleControl.SetMode(inputHandle, mode); } } else { ConsoleHostRawUserInterface.KEY_EVENT_RECORDToKeyInfo(this.cachedKeyEvent, out keyInfo); this.cachedKeyEvent.RepeatCount = (ushort)(this.cachedKeyEvent.RepeatCount - 1); } if ((options & ReadKeyOptions.NoEcho) == 0) { char character = keyInfo.Character; this.parent.WriteToConsole(character.ToString(CultureInfo.CurrentCulture), true); } return keyInfo; } else { throw PSTraceSource.NewArgumentException("options", "ConsoleHostRawUserInterfaceStrings", "InvalidReadKeyOptionsError", new object[0]); } }