public void BasicUsagePasses() { var screenSize = new Vector2Int(128, 128); var inputRecord = InputRecord.Create(screenSize); Assert.AreEqual(screenSize, inputRecord.ScreenSize); for (var i = 0; i < 10; ++i) { var frame = new InputRecord.Frame((uint)i, 16f / 1000f); frame.SetInputTextByJson(new FrameData { n = i, s = $"msg{i}" }); inputRecord.Push(frame); } Assert.AreEqual(10, inputRecord.FrameCount); Assert.IsTrue(inputRecord.Frames.Any()); //Frameデータのクリアー処理 inputRecord.ClearFrames(); Assert.AreEqual(screenSize, inputRecord.ScreenSize); Assert.AreEqual(0, inputRecord.FrameCount); Assert.IsFalse(inputRecord.Frames.Any()); }
public bool towerPrediction() { if (defends.defends.Count == 0) { return(false); } //current state of the game InputRecord gameState = m.gsr.getGameState(); int bestDistIdx = 0; float bestDist = float.MaxValue; for (int i = 0; i < defends.defends.Count; i++) { float dist = getDistFromCurrentState(gameState, defends.defends[i].input); if (dist < bestDist) { bestDist = dist; bestDistIdx = i; } else if (dist == bestDist) { bestDistIdx = Random.Range(0, 2) == 0 ? i : bestDistIdx; } } if (bestDist < 3.0f) { m.autoplay.createTower(defends.defends[bestDistIdx].output); modifyDefenceOutput(bestDistIdx); return(true); } return(false); }
protected override void OnProcessRecord(InputRecord record) { MouseEventRecord mouseRecord = record.MouseEvent; m_PosX = mouseRecord.MousePosition.X; m_PosY = mouseRecord.MousePosition.Y; if ((mouseRecord.EventFlags & 0x004) != 0) //vertical { if (mouseRecord.ButtonState == FORWARD_SCROLL) { m_Scroll = 1; m_IsActive = true; } else if (mouseRecord.ButtonState == BACKWARD_SCROLL) { m_Scroll = -1; m_IsActive = true; } } else { m_ButtomState = mouseRecord.ButtonState; } }
protected override void OnProcessRecord(InputRecord record) { KeyEventRecord keyRecord = record.KeyEvent; if (keyRecord.KeyDown) { m_Pressed.Add(keyRecord.VirtualKeyCode); } else { m_Pressed.Remove(keyRecord.VirtualKeyCode); } uint modifier = keyRecord.ControlKeyState; for (int x = 0; x < MODIFIERS.Length; ++x) { int offseted = 1 << (int)x; if ((modifier & offseted) != 0) { if (keyRecord.KeyDown) { m_Pressed.Add(x); } } else { m_Pressed.Remove(x); } } }
private InputService CreateInputService <T>(InputRecord in1, InputRecord in2, Action <T> @out) where T : class { var inPipe = A.Fake <IPipe>(); A.CallTo(() => inPipe.WriteAsync(A <ITransferable> ._, A <bool> ._, A <CancellationToken> ._)) .Invokes(x => @out(x.Arguments[0] as T)); var activeTerminal = A.Fake <ITerminal>(); A.CallTo(() => activeTerminal.In).Returns(inPipe); var terminalContainer = A.Fake <ITerminalContainer>(); A.CallTo(() => terminalContainer.ActiveTerminal).Returns(activeTerminal); var kernel32Api = A.Fake <IKernel32Api>(); var counter = 0; A.CallTo(() => kernel32Api.ReadConsoleInput()).ReturnsLazily(x => counter++ == 0 ? in1 : in2); var configuration = A.Fake <IWinTerMulConfiguration>(); A.CallTo(() => configuration.PrefixKey).Returns(PrefixKeyString); A.CallTo(() => configuration.ClosePaneKey).Returns(ClosePaneKey); return(new InputService( terminalContainer, kernel32Api, configuration, A.Fake <ITerminalFactory>())); }
public void PrefixKeyThenClosePaneKey_CloseCommandIsSent() { // Arrange var prefixKey = new InputRecord(); prefixKey.Event.KeyEvent.Char.UnicodeChar = (char)PrefixKey; prefixKey.Event.KeyEvent.Char.AsciiChar = PrefixKey; prefixKey.EventType = InputEventTypeFlag.KeyEvent; var closePaneKey = new InputRecord(); closePaneKey.Event.KeyEvent.Char.UnicodeChar = ClosePaneKey; closePaneKey.Event.KeyEvent.Char.AsciiChar = (byte)ClosePaneKey; closePaneKey.EventType = InputEventTypeFlag.KeyEvent; CloseCommand closeCommand = null; var inputService = CreateInputService <CloseCommand>( prefixKey, closePaneKey, x => closeCommand = x); // Act inputService.HandleInputAsync().Wait(); inputService.HandleInputAsync().Wait(); // Assert Assert.IsNotNull(closeCommand); }
public void PollEvents(Action <InputRecord> inputEventHandler) { if (OriginalConsoleMode != 0) { return; } OriginalConsoleMode = ConsoleMode; ConsoleMode |= (uint)ConsoleModes.EnableMouseInput; ConsoleMode &= ~(uint)ConsoleModes.EnableQuickEditMode; ConsoleMode |= (uint)ConsoleModes.EnableExtendedFlags; Task.Run(() => { uint numberEventsRead = 0; uint length = 1; InputRecord[] records = new InputRecord[length]; while (ContinueListeningForConsoleEvents && ReadConsoleInput(InputHandle, records, length, out numberEventsRead) && numberEventsRead > 0) { inputEventHandler(records[0]); } }); }
protected override void GetInputs() { GlobalInputManager gim = GlobalInputManager.instance; InputRecordItem recordItem = new InputRecordItem(); recordItem.AddInput((int)EntityInputs.Movement, new InputRecordAxis2D(gim.GetAxis2D(ControllerID, Action.Movement_X, Action.Movement_Y))); recordItem.AddInput((int)EntityInputs.Camera, new InputRecordAxis2D(gim.GetAxis2D(ControllerID, Action.Camera_X, Action.Camera_Y))); recordItem.AddInput((int)EntityInputs.Float, new InputRecordAxis(gim.GetAxis(ControllerID, Action.Float))); recordItem.AddInput((int)EntityInputs.Lockon, new InputRecordButton(gim.GetButton(ControllerID, Action.Lock_On))); recordItem.AddInput((int)EntityInputs.Interact, new InputRecordButton(gim.GetButton(ControllerID, Action.Interact))); recordItem.AddInput((int)EntityInputs.Bullet, new InputRecordButton(gim.GetButton(ControllerID, Action.Bullet))); recordItem.AddInput((int)EntityInputs.Attack, new InputRecordButton(gim.GetButton(ControllerID, Action.Attack))); recordItem.AddInput((int)EntityInputs.Special, new InputRecordButton(gim.GetButton(ControllerID, Action.Special))); recordItem.AddInput((int)EntityInputs.Dash, new InputRecordButton(gim.GetButton(ControllerID, Action.Dash))); recordItem.AddInput((int)EntityInputs.Jump, new InputRecordButton(gim.GetButton(ControllerID, Action.Jump))); recordItem.AddInput((int)EntityInputs.Taunt, new InputRecordButton(gim.GetButton(ControllerID, Action.Taunt))); InputRecord.Add(recordItem); }
public virtual void TASSyntaxHighlight(Range range) { RichText tb = range.tb; tb.CommentPrefix = "#"; tb.LeftBracket = '\x0'; tb.RightBracket = '\x0'; tb.LeftBracket2 = '\x0'; tb.RightBracket2 = '\x0'; //clear style of changed range range.ClearStyle(GrayStyle, GreenStyle, RedStyle, BlueStyle, PinkStyle); int start = range.Start.iLine; int end = range.End.iLine; if (start > end) { int temp = start; start = end; end = temp; } while (start <= end) { int charEnd = tb[start].Count; Range line = new Range(tb, 0, start, charEnd, start); InputRecord input = new InputRecord(line.Text); if (input.Frames == 0 && input.Actions == Actions.None) { line.SetStyle(GreenStyle); } else { Range sub = new Range(tb, 0, start, 4, start); sub.SetStyle(RedStyle); int charStart = 4; while (charStart < charEnd) { sub = new Range(tb, charStart, start, charStart + 1, start); char c = tb[start][charStart].c; if (c == InputRecord.Delimiter) { sub.SetStyle(GrayStyle); } else { sub.SetStyle(BlueStyle); } charStart++; } } start++; } }
/// <summary> /// tracks all entities to get the current state of the game /// </summary> /// <returns>struct containing all pertinent data</returns> public InputRecord getGameState() { InputRecord input = new InputRecord() { walls = new List <EntityData>(), units = new List <EntityData>(), towers = new List <EntityData>(), }; foreach (Structure wall in walls) { Vector2Int iPos = getGridPos(wall.transform.position); Vector2 pos = normalisePos(iPos); EntityData wallData = new EntityData() { x = pos.x, y = pos.y, type = new short[0], health = wall.getHealth() }; input.walls.Add(wallData); } foreach (Unit unit in m.tracker.getUnits()) { Vector2Int iPos = getGridPos(unit.transform.position); Vector2 pos = normalisePos(iPos); EntityData unitData = new EntityData() { x = pos.x, y = pos.y, health = unit.getHealth(), type = new short[(int)UnitType.Count] }; unitData.type[(int)unit.getType()] = 1; input.units.Add(unitData); } foreach (Tower tower in m.tracker.getTowers()) { if (tower.isReady()) { Vector2Int iPos = getGridPos(tower.transform.position); Vector2 pos = normalisePos(iPos); EntityData towerData = new EntityData() { x = pos.x, y = pos.y, health = tower.getHealth(), type = new short[(int)TowerType.Count] }; towerData.type[(int)tower.getType()] = 1; input.towers.Add(towerData); } } input.attackerResources = m.tracker.getResources(true).normalisedValue(); input.defenderResources = m.tracker.getResources(false).normalisedValue(); return(input); }
public void ProcessRecord(InputRecord record) { if (Enabled) { m_IsActive = true; m_AnyKeyPressed = true; OnProcessRecord(record); } }
private void SetCurrentRecord() { if (_inputQueue.Count > 0) { _currentRecord = _inputQueue.Dequeue(); } else { _currentRecord = new InputRecord(Vector3.zero, InputState.None); } }
private void tasText_LineRemoved(object sender, LineRemovedEventArgs e) { int count = e.Count; while (count-- > 0) { InputRecord input = Lines[e.Index]; totalFrames -= input.Frames; Lines.RemoveAt(e.Index); } UpdateStatusBar(); }
private void tasText_LineInserted(object sender, LineInsertedEventArgs e) { RichText tas = (RichText)sender; int count = e.Count; while (count-- > 0) { InputRecord input = new InputRecord(tas.GetLineText(e.Index + count)); Lines.Insert(e.Index, input); totalFrames += input.Frames; } UpdateStatusBar(); }
protected override void GetInputs() { InputRecordItem recordItem = new InputRecordItem(); recordItem.AddInput((int)EntityInputs.MOVEMENT, new InputRecordAxis2D(new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")))); recordItem.AddInput((int)EntityInputs.JUMP, new InputRecordButton(Input.GetKey(KeyCode.K))); recordItem.AddInput((int)EntityInputs.DASH, new InputRecordButton(Input.GetKey(KeyCode.LeftShift))); recordItem.AddInput((int)EntityInputs.ATTACK, new InputRecordButton(Input.GetKey(KeyCode.I))); InputRecord.Add(recordItem); }
/// <summary> /// when a tower is added by its data, /// this is called to add the game state /// and the new tower to the list of /// game data /// </summary> /// <param name="tower">data of the new tower</param> public void towerAdded(EntityData tower) { if (pathOut == -1) { return; } InputRecord _in = getGameState(); IODSetup data = new IODSetup() { frame = m.frames.frame, input = _in, output = tower }; defends.defends.Add(data); }
/// <summary> /// when a unit is added by their data, /// this is called to add the game /// state and the new unit to the list /// of game data /// </summary> /// <param name="unit">the data of the unit added</param> public void unitAdded(UnitData unit) { if (pathOut == -1) { return; } InputRecord _in = getGameState(); IOASetup data = new IOASetup() { frame = m.frames.frame, input = _in, output = unit }; attacks.attacks.Add(data); }
public void IsNotKeyEvent_NoInputDataWritten() { // Arrange var inputRecord = new InputRecord { EventType = InputEventTypeFlag.FocusEvent }; InputRecord?writtenInputRecord = null; var inputService = CreateInputService <InputData>( inputRecord, x => writtenInputRecord = x?.InputRecord); // Act inputService.HandleInputAsync().Wait(); // Assert Assert.IsNull(writtenInputRecord); }
float getDistFromCurrentState(InputRecord currentInput, InputRecord previousInput) { float dist = 0; foreach (EntityData tower in currentInput.towers) { dist += findClosest(tower, previousInput.towers); } foreach (EntityData unit in currentInput.units) { dist += findClosest(unit, previousInput.units); } foreach (EntityData wall in currentInput.walls) { dist += findClosest(wall, previousInput.walls); } dist += Mathf.Pow(currentInput.attackerResources - previousInput.attackerResources, 2); dist += Mathf.Pow(currentInput.defenderResources - previousInput.defenderResources, 2); return(dist); }
public void unitPrediction() { //current state of the game InputRecord gameState = m.gsr.getGameState(); int bestDistIdx = 0; float bestDist = float.MaxValue; for (int i = 0; i < attacks.attacks.Count; i++) { float dist = getDistFromCurrentState(gameState, attacks.attacks[i].input); dist -= attacks.score; if (dist < bestDist) { bestDist = dist; bestDistIdx = i; } } m.autoplay.createUnit(attacks.attacks[bestDistIdx].output); }
private async Task <bool> HandlePrefixKeyAsync(InputRecord inputRecord) { if (_wasLastKeyPrefixKey) { _wasLastKeyPrefixKey = false; var unicodeChar = inputRecord.Event.KeyEvent.Char.UnicodeChar; if (_charactersToIgnoreAfterPrefixKey.Contains(unicodeChar)) { _wasLastKeyPrefixKey = true; } else if (unicodeChar == _configuration.SetNextTerminalActiveKey) { _terminalContainer.SetNextTerminalActive(); } else if (unicodeChar == _configuration.SetPreviousTerminalActive) { _terminalContainer.SetPreviousTerminalActive(); } else if (unicodeChar == _configuration.VerticalSplitKey) { _terminalContainer.AddTerminal(_terminalFactory.CreateTerminal()); } else if (unicodeChar == _configuration.ClosePaneKey) { await _terminalContainer.ActiveTerminal?.In?.WriteAsync(new CloseCommand()); } return(true); } if (inputRecord.Event.KeyEvent.Char.UnicodeChar == _prefixKey) { _wasLastKeyPrefixKey = true; return(true); } return(false); }
public void IsKeyEvent_InputDataIsWrittenToActiveTerminal() { // Arrange var inputRecord = new InputRecord(); inputRecord.Event.KeyEvent.Char.AsciiChar = 99; inputRecord.Event.KeyEvent.Char.UnicodeChar = 'c'; inputRecord.EventType = InputEventTypeFlag.KeyEvent; InputRecord?writtenInputRecord = null; var inputService = CreateInputService <InputData>( inputRecord, x => writtenInputRecord = x?.InputRecord); // Act inputService.HandleInputAsync().Wait(); // Assert var expectedJson = JsonConvert.SerializeObject(inputRecord); var actualJson = JsonConvert.SerializeObject(writtenInputRecord); Assert.AreEqual(expectedJson, actualJson); }
/// <summary> /// Gets metadata for a particular entity based on its name using Ayalon /// </summary> /// <param name="entityName">The name of the entity to extract data for.</param> /// <returns>Asynchronous task that returns entity data. </returns> private async static Task <OutputRecord.OutputRecordData> GetEntityMetadata(InputRecord inputRecord) { var uri = ayalonEndpoint + "/query"; var result = new OutputRecord.OutputRecordData(); using (var client = new HttpClient()) using (var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri(uri) }) { var serializerSettings = new JsonSerializerSettings(); serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); var data = new AyalonInputRecord { Documents = new AyalonDocument[] { new AyalonDocument { Id = inputRecord.RecordId, Text = inputRecord.Data.Document } } }; var json = JsonConvert.SerializeObject(data, serializerSettings); var stringContent = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); request.Content = stringContent; HttpResponseMessage response = await client.SendAsync(request); string responseBody = await response?.Content?.ReadAsStringAsync(); AyalonResponse[] ayalonResponses = JsonConvert.DeserializeObject <AyalonResponse[]>(responseBody); if (ayalonResponses != null) { return(AddEnrichedMetadata(ayalonResponses[0], inputRecord.Data.Document).Result); } } return(result); }
private void UpdateDevices() { Keyboard.UpdateState(); Mouse.UpdateState(); if (ConsoleHelper.ReadAvail() > 0) { uint size = ConsoleHelper.ReadInput(m_Buffer); for (int x = 0; x < size; ++x) { InputRecord record = m_Buffer[x]; switch (record.EventType) { case EInputEvent.MouseEvent: Mouse.ProcessRecord(record); break; case EInputEvent.KeyEvent: Keyboard.ProcessRecord(record); break; } } } }
public HttpResponseMessage SavePersonRecord([FromBody] InputRecord inputRequest) { if (inputRequest == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "INVALID_PARAM: INUPUT REQUEST IS NULL")); } if (inputRequest.Line == "") { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "INVALID_PARAM:INPUT LINE IS EMPTY")); } if (!Enum.IsDefined(typeof(FormatEnum), inputRequest.Delimiter)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "INVALID_PARAM: DELIMITER")); } Person person = new Person(); person = _dataParser.GetPersonDetails(inputRequest.Delimiter, inputRequest.Line); _personDataCacheModel.Persons.Add(person); ApiResponse apiResponse = new ApiResponse(); apiResponse.MessageText = "Success"; return(Request.CreateResponse(HttpStatusCode.OK, apiResponse)); }
private static extern bool ReadConsoleInput(IntPtr consoleInputHandle, out InputRecord inputRecord, int recordCount, out int numberOfEventsRead);
public InputProcessedMessage(InputRecord inputRecord) { InputRecord = inputRecord; }
private InputService CreateInputService <T>(InputRecord @in, Action <T> @out) where T : class { return(CreateInputService(@in, default(InputRecord), @out)); }
/// <summary> /// Reads data from a console input buffer and removes it from the buffer. /// </summary> /// <param name="hConsoleInput"> /// [in] A handle to the console input buffer. The handle must have the <see cref="ConsoleAccess.GENERIC_READ"/> /// access right. /// </param> /// <param name="nLength"> /// [in] The size of the array buffer, in array elements. /// </param> /// <returns> /// An array of <see cref="InputRecord"/> structures that receives the input buffer data. /// </returns> public static InputRecord[] ReadConsoleInput( SafeConsoleHandle hConsoleInput, uint nLength) { uint lpNumberOfEventsRead; var lpBuffer = new InputRecord[nLength]; WinError.ThrowLastWin32ErrorIfFailed( ReadConsoleInput(hConsoleInput, lpBuffer, nLength, out lpNumberOfEventsRead)); Array.Resize(ref lpBuffer, (int)lpNumberOfEventsRead); return lpBuffer; }
/// <summary> /// Handles input data from client. /// </summary> /// <param name="record">The underlying record.</param> protected void HandleInputData(InputRecord record) { var maxBodyLen = this.Server._SETTINGS.MaxBodyLength; if (maxBodyLen < 0) { maxBodyLen = 0; } var dataToWriteCount = record.Data.Length; if (maxBodyLen.HasValue) { if ((this._CONTEXT.BodyStream.Length + dataToWriteCount) > maxBodyLen) { // truncate dataToWriteCount = (int)(maxBodyLen.Value - this._CONTEXT.BodyStream.Length); } } if (dataToWriteCount > 0) { var dataToWrite = record.Data; if (dataToWrite.Length > dataToWriteCount) { dataToWrite = dataToWrite.Take(dataToWriteCount).ToArray(); } using (var temp = new MemoryStream(dataToWrite, false)) { if (!this._CONTEXT.WriteBufferSize.HasValue) { temp.CopyTo(this._CONTEXT.BodyStream); } else { temp.CopyTo(this._CONTEXT.BodyStream, this._CONTEXT.WriteBufferSize.Value); } } } else { var handler = this.Server._SETTINGS.Handler; if (handler != null) { handler.HandleRequest(this._CONTEXT); } else { this._CONTEXT.End(); } if (!this.HasEnded) { this.HandleNext(); } } }
private void tasText_LineNeeded(object sender, LineNeededEventArgs e) { InputRecord record = new InputRecord(e.SourceLineText); e.DisplayedLineText = record.ToString(); }
/// <summary> /// Writes data directly to the console input buffer. /// </summary> /// <param name="hConsoleInput"> /// [in] A handle to the console input buffer. The handle must have the <see cref="ConsoleAccess.GENERIC_WRITE"/> /// access right. /// </param> /// <param name="lpBuffer"> /// [in] A pointer to an array of <see cref="InputRecord"/> structures that contain data to be written to the /// input buffer. /// </param> /// <param name="nLength"> /// [in] The number of input records to be written. /// </param> /// <returns>The number of input records actually written.</returns> public static uint WriteConsoleInput(SafeConsoleHandle hConsoleInput, InputRecord[] lpBuffer, uint nLength) { uint lpNumberOfEventsWritten; WinError.ThrowLastWin32ErrorIfFailed( WriteConsoleInput(hConsoleInput, lpBuffer, nLength, out lpNumberOfEventsWritten)); return lpNumberOfEventsWritten; }
private void UpdateLines(RichText tas, Range range) { if (updating) { return; } updating = true; int start = range.Start.iLine; int end = range.End.iLine; while (start <= end) { InputRecord old = Lines.Count > start ? Lines[start] : null; string text = tas[start++].Text; InputRecord input = new InputRecord(text); if (old != null) { totalFrames -= old.Frames; string line = input.ToString(); if (text != line) { if (old.Frames == 0 && old.ZeroPadding == input.ZeroPadding && old.Equals(input) && line.Length >= text.Length) { line = string.Empty; } Range oldRange = tas.Selection.Clone(); tas.Selection = tas.GetLine(start - 1); tas.SelectedText = line; int actionPosition = input.ActionPosition(); if (!string.IsNullOrEmpty(line)) { int index = oldRange.Start.iChar + line.Length - text.Length; if (index < 0) { index = 0; } if (index > 4 && old.Angle == input.Angle) { index = 4; } if (old.Frames == input.Frames && old.ZeroPadding == input.ZeroPadding && old.Angle == input.Angle) { index = 4; } tas.Selection.Start = new Place(index, start - 1); } Text = titleBarText + " ***"; } Lines[start - 1] = input; } totalFrames += input.Frames; } UpdateStatusBar(); updating = false; }
internal static extern bool ReadConsoleInput(IntPtr hConsoleInput, out InputRecord buffer, int numInputRecords_UseOne, out int numEventsRead);
public static extern bool ReadConsoleInput( SafeFileHandle hConsoleInput, InputRecord[] lpBuffer, int nLength, ref int lpNumberOfEventsRead );
internal static void Wait4Keypress() { bool done = false; IntPtr stdin = GetStdHandle(Constants.StdError); uint eventsRead; InputRecord[] records = new InputRecord[1]; if (stdin == Constants.InvalidHandle) throw new Exception("Unable to aquire the standard input handle."); while (!done) { GetNumberOfConsoleInputEvents(stdin, out eventsRead); if (eventsRead > 0) { IO.ErrorWriteLine("events"+eventsRead.ToString()); if (PeekConsoleInput(stdin, records, (uint)records.Length, out eventsRead)) { // Check for a keyborad event if (records[0].eventType == EventTypes.MouseEvent) break; // else // consume non keybord event; // ReadConsoleInput(stdin, records, (uint)records.Length, out eventsRead); } } else { Thread.Sleep(100); } } }
private void UpdateLines(RichText tas, Range range) { if (updating) { return; } updating = true; int start = range.Start.iLine; int end = range.End.iLine; if (start > end) { int temp = start; start = end; end = temp; } int originalStart = start; bool modified = false; StringBuilder sb = new StringBuilder(); Place place = new Place(0, end); while (start <= end) { InputRecord old = Lines.Count > start ? Lines[start] : null; string text = tas[start++].Text; InputRecord input = new InputRecord(text); if (old != null) { totalFrames -= old.Frames; string line = input.ToString(); if (text != line) { if (old.Frames == 0 && input.Frames == 0 && old.ZeroPadding == input.ZeroPadding && old.Equals(input) && line.Length >= text.Length) { line = string.Empty; } Range oldRange = tas.Selection; if (!string.IsNullOrEmpty(line)) { int index = oldRange.Start.iChar + line.Length - text.Length; if (index < 0) { index = 0; } if (index > 4) { index = 4; } if (old.Frames == input.Frames && old.ZeroPadding == input.ZeroPadding) { index = 4; } place = new Place(index, start - 1); } modified = true; } else { place = new Place(4, start - 1); } text = line; Lines[start - 1] = input; } else { place = new Place(text.Length, start - 1); } if (start <= end) { sb.AppendLine(text); } else { sb.Append(text); } totalFrames += input.Frames; } if (modified) { tas.Selection = new Range(tas, 0, originalStart, tas[end].Count, end); tas.SelectedText = sb.ToString(); tas.Selection = new Range(tas, place.iChar, end, place.iChar, end); Text = titleBarText + " ***"; } UpdateStatusBar(); updating = false; }
public static extern bool WriteConsoleInput( SafeConsoleHandle hConsoleInput, InputRecord[] lpBuffer, uint nLength, out uint lpNumberOfEventsWritten);
public static void Enqueue(InputRecord inputRecord) { if (inputRecord.InputState != InputState.None) currentQueue.Add(inputRecord); }
internal static partial bool ReadConsoleInput(IntPtr hConsoleInput, out InputRecord buffer, int numInputRecords_UseOne, out int numEventsRead);
static bool KeyPressed() { var stdin = Kernel32.GetStdHandle(-10); int count; if (!Kernel32.GetNumberOfConsoleInputEvents(stdin, out count)) throw new Win32Exception(); if (count > 0) { InputRecord[] buf = new InputRecord[count]; if (!Kernel32.ReadConsoleInput(stdin, buf, buf.Length, out count)) throw new Win32Exception(); for (int i = 0; i < count; i++) { if (buf[i].EventType == 1 && !buf[i].KeyEvent.bKeyDown) return true; } } return false; }