void IInput.KeyInputted(ConsoleKeyInfo key) { if (key.Key == ConsoleKey.Enter) { if (Suggestion != null) { LastInput.Enqueue(Suggestion); } else { LastInput.Enqueue(CurrentInput); } CurrentInput = ""; Suggestion = null; currentSuggestion = -1; } else if (key.Key == ConsoleKey.Escape) { CurrentInput = ""; Suggestion = null; currentSuggestion = -1; } else if (key.Key == ConsoleKey.Backspace) { if (CurrentInput.Length > 0) { CurrentInput = CurrentInput.Substring(0, CurrentInput.Length - 1); suggestions = AutoCompleteWordList.Where(x => x.StartsWith(CurrentInput)).ToList(); } Suggestion = null; currentSuggestion = -1; } else if (key.Key == ConsoleKey.Tab) { currentSuggestion++; if (currentSuggestion > suggestions.Count - 1) { currentSuggestion = -1; Suggestion = null; } else { Suggestion = suggestions[currentSuggestion]; } } else { if (Suggestion != null) { CurrentInput = Suggestion += key.KeyChar; } else { CurrentInput += key.KeyChar; } suggestions = AutoCompleteWordList.Where(x => x.StartsWith(CurrentInput)).ToList(); Suggestion = null; currentSuggestion = -1; } }
public static void OffIfIdle(int idleTimeMs, bool mute) { if (LastInput.GetLastInputAgeMs() >= idleTimeMs) { Off(mute); } }
public IHttpActionResult GetLastInputs(short branchNo) { try { var inputs = new LastInput(); using (var context = new Context()) { var customersTypes = context.Customers_Types.Where(b => b.Branch_No == branchNo).ToList(); inputs.CustomersTypes = AutoMapperConfig.Mapper.Map <List <Customers_TypesDto> >(customersTypes); var customers = context.Customers.Where(b => b.Branch_No == branchNo).ToList(); inputs.Customers = AutoMapperConfig.Mapper.Map <List <CustomerDto> >(customers); var customersAddres = context.Customers_Address.Where(b => b.Branch_No == branchNo).ToList(); inputs.CustomersAddres = AutoMapperConfig.Mapper.Map <List <Customers_AddressDto> >(customersAddres); return(Ok(new AjaxResponse <object>() { Success = true, LastInput = inputs })); } } catch (Exception e) { return(Ok(new AjaxResponse <object>() { Success = false, ErrorMessage = $"In web api Can not get data from server in GetLastInputs .. {e.GetLastException()} " })); } }
// Update is called once per frame void FixedUpdate() { xInput = Input.GetAxisRaw("Horizontal"); if (xInput != 0) { dir = new Vector2(xInput * speed, 0); if (xInput > 0) { anim.SetTrigger("MoveRight"); lastInput = LastInput.right; } else { anim.SetTrigger("MoveLeft"); lastInput = LastInput.left; } } else { dir = new Vector2(0, 0); SetIdleAnimTriggers(); } rb2d.velocity = dir; }
public string EqualExpression() { return((OperateSelector == null) ? LastResult.ToString() + "=" : BaseNumber.ToString() + OperateSelector.Mark() + LastInput.ToString() + "="); }
/// <summary> /// Returns the the first input in the queue, if any. Throws exception if there is no input to consume. /// </summary> /// <returns></returns> public string Consume() { if (HasInput) { var returnValue = LastInput.Dequeue(); return(returnValue); } else { throw new InvalidOperationException("There's no input to consume"); } }
private static void WaitForWakeProcedure(object arg) { try { dynamic args = arg; uint lastInputAge = args.lastInputAge; Stopwatch sleepTimer = Stopwatch.StartNew(); int timesToSetOff = 12; // In theory the last input counter will roll over after 49.7102696 days. Or maybe it'll just stop incrementing? Either way, lets hope the PC doesn't stay idle that long. while (true) { uint inputAge = LastInput.GetLastInputAgeMs(); if (inputAge < lastInputAge || currentMonitorStatus != "off") { break; } lastInputAge = inputAge; Thread.Sleep(1000); if (timesToSetOff > 0 && sleepTimer.ElapsedMilliseconds >= 5000) { sleepTimer.Restart(); timesToSetOff--; SetMonitorInState(2); } } bool doPartialWakeLogic = Program.settings.inputsRequiredToWake > 1 && currentMonitorStatus == "off"; bool lastOffDidMute = didMute; currentMonitorStatus = "on"; UnmuteIfNeeded(); if (doPartialWakeLogic) { PartialWakeLogic(lastOffDidMute); } } catch (ThreadAbortException) { } catch (Exception ex) { Logger.Debug(ex); } }
private static void PartialWakeLogic(bool mute, int totalInputs = 1, PartialWakeNotifier pwn = null, int iterations = 0) { double inputsRequired = BPMath.Clamp(Program.settings.inputsRequiredToWake, 1, 50); const int maxIterations = 100; const int iterationInterval = 100; if (totalInputs >= inputsRequired) { // Input requirements met. Full Wake. if (pwn != null) { pwn.Terminate(); } } else if (iterations < maxIterations) { // Waiting for more inputs. if (pwn == null) { pwn = new PartialWakeNotifier(); pwn.Progress = (int)((totalInputs / inputsRequired) * 100); SetTimeout.OnBackground(() => { Application.Run(pwn); }, 0); } pwn.SetSecondsRemaining((int)(((maxIterations - iterations) * iterationInterval) / 1000.0)); SetTimeout.OnBackground(() => { if (LastInput.GetLastInputAgeMs() < maxIterations) { totalInputs++; pwn.Progress = (int)((totalInputs / inputsRequired) * 100); } PartialWakeLogic(mute, totalInputs, pwn, iterations + 1); }, iterationInterval); } else { // Input requires not met. Go back to sleep. if (pwn != null) { pwn.Terminate(); } Off(mute); } }
/// <summary> /// Dump a Mismatch if debugging /// </summary> /// <param name="String">Mismatched String</param> internal static void Missmatch(string String) { try { if (!String.IsDialog() && DumpStrOnly) { return; } string Txt = SimplfyMatch(String); if (ContainsMissed(Txt) || InCache(Txt)) { return; } if (LastInput.EndsWith(String)) { return; } if (Ranges != null && DialogCheck) { uint Miss = 0; foreach (char c in Txt) { if (!InRange(c)) { Miss++; } } if (Miss >= Txt.Length - 3) { return; } } AddMissed(Txt); Txt = TrimString(String); AppendLst(Txt, Txt, TLMapSrc + StrLstSufix); } catch { } }
public static void Off(bool mute) { UnmuteIfNeeded(); currentMonitorStatus = "off"; SetMonitorInState(2); uint lastInputAge = LastInput.GetLastInputAgeMs(); lock (myLock) { didMute = false; if (mute && !AudioManager.GetMasterVolumeMute()) { AudioManager.SetMasterVolumeMute(true); didMute = true; } StopMonitorOffThread(); StopWaitForWakeThread(); StartWaitForWakeThread(new { lastInputAge }); } }
//二元运算符(加 减 乘 除) private void buttonBinaryOperators_Click(object sender, EventArgs e) { //出错后只可清除 if (isError) { System.Media.SystemSounds.Beep.Play(); return; } if (typeLastInput == LastInput.number) currentNumber = double.Parse(currentText); if (previousInputs.Count == 0) previousInputs.Add(currentNumber.ToString()); if (typeLastInput == LastInput.number || typeLastInput == LastInput.unaryOperators) if (previousInputs.Count > 1) { binaryNumber = currentNumber; currentNumber = BinaryCalc(previousNumber); } if (typeLastInput == LastInput.binaryOperators) previousInputs.RemoveAt(previousInputs.Count - 1); previousNumber = currentNumber; //设置二元运算符 binaryOperator = (sender as Button).Text; previousInputs.Add(binaryOperator); //等待操作数 binaryNumber = null; currentText = currentNumber.ToString(); //按了二元运算符 typeLastInput = LastInput.binaryOperators; }
// Update is called once per frame void FixedUpdate() { if (!interacting) { xInput = Input.GetAxisRaw("Horizontal"); yInput = Input.GetAxisRaw("Vertical"); //Vector3 dir = new Vector2(xInput, yInput) * speed; if (xInput != 0) { dir = new Vector2(xInput * speed, 0); if (xInput > 0) { anim.SetTrigger("MoveRight"); lastInput = LastInput.right; } else { anim.SetTrigger("MoveLeft"); lastInput = LastInput.left; } } else if (yInput != 0) { dir = new Vector2(0, yInput * speed); if (yInput > 0) { anim.SetTrigger("MoveUp"); lastInput = LastInput.up; } else { anim.SetTrigger("MoveDown"); lastInput = LastInput.down; } } else { dir = new Vector2(0, 0); SetIdleAnimTriggers(); } rb2d.velocity = dir; if (dir == Vector3.zero) { dir = previousGood; } else { previousGood = dir; } if (Input.GetButtonDown("Jump")) { foundHit = Physics2D.Raycast(transform.position, dir, checkDist, 1 << LayerMask.NameToLayer("Wall")); Debug.DrawRay(transform.position, dir, Color.green); if (foundHit.collider != null) { Debug.Log("Looking at a thing: " + foundHit.transform.name); foundHit.collider.gameObject.GetComponent <Object_Interact_Parent>().Interact(); interacting = true; } } } else { SetIdleAnimTriggers(); } }
//清除所有 private void buttonClear_Click(object sender, EventArgs e) { isError = false; previousInputs.Clear(); currentText = "0"; currentNumber = 0; previousNumber = 0; binaryOperator = null; binaryNumber = null; typeLastInput = LastInput.number; }
public override void handleGETRequest(HttpProcessor p) { if (!Program.settings.IpIsWhitelisted(p.RemoteIPAddressStr)) { p.writeFailure("403 Forbidden"); return; } string successMessage = "<div>" + p.requestedPage + " command successful</div>"; List <KeyValuePair <string, string> > additionalHeaders = new List <KeyValuePair <string, string> >(); additionalHeaders.Add(new KeyValuePair <string, string>("Access-Control-Allow-Origin", "*")); if (p.requestedPage == "on") { On(p); } else if (p.requestedPage == "off") { int idleTimeMs = p.GetIntParam("ifidle", 0); int delayMs = p.GetIntParam("delay", 0); Action setOff = () => { if (idleTimeMs <= 0 || LastInput.GetLastInputAgeMs() >= idleTimeMs) { Off(p.GetBoolParam("mute")); } }; if (delayMs > 0) { SetTimeout.OnBackground(setOff, delayMs); } else { setOff(); } } else if (p.requestedPage == "off_if_idle") { OffIfIdle(Program.settings.idleTimeMs, p.GetBoolParam("mute")); } else if (p.requestedPage == "standby") { currentMonitorStatus = "off"; SetMonitorInState(1); } else if (p.requestedPage == "status") { p.writeSuccess("text/plain", additionalHeaders: additionalHeaders); p.outputStream.Write(currentMonitorStatus); return; } else if (p.requestedPage == "idle") { p.writeSuccess("text/plain", additionalHeaders: additionalHeaders); p.outputStream.Write(LastInput.GetLastInputAgeMs()); return; } else if (p.requestedPage == "smarttoggle") { if (currentMonitorStatus == "on") { OffIfIdle(Program.settings.idleTimeMs, p.GetBoolParam("mute")); } else { On(p); } } else if (p.requestedPage == "cancel") { StopMonitorOffThread(); } else if (p.requestedPage == "getvolume") { int level = 0; try { level = (int)Math.Round(AudioManager.GetMasterVolume()); //level = Audio.GetVolume(); } catch (Exception ex) { p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error"); p.outputStream.Write(ex.ToString()); return; } p.writeSuccess("text/plain"); p.outputStream.Write(level); } else if (p.requestedPage == "setvolume") { int level = p.GetIntParam("level"); level = level.Clamp(0, 100); try { AudioManager.SetMasterVolume(level); //Audio.SetVolume(level); } catch (Exception ex) { p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error"); p.outputStream.Write(ex.ToString()); return; } p.writeSuccess("text/plain"); p.outputStream.Write(level); } else if (p.requestedPage == "mute") { try { AudioManager.SetMasterVolumeMute(true); //Audio.SetMute(true); } catch (Exception ex) { p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error"); p.outputStream.Write(ex.ToString()); return; } p.writeSuccess("text/plain"); p.outputStream.Write("muted"); } else if (p.requestedPage == "unmute") { try { AudioManager.SetMasterVolumeMute(false); //Audio.SetMute(false); } catch (Exception ex) { p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error"); p.outputStream.Write(ex.ToString()); return; } p.writeSuccess("text/plain"); p.outputStream.Write("unmuted"); } else if (p.requestedPage == "getmute") { bool muted = false; try { muted = AudioManager.GetMasterVolumeMute(); //muted = Audio.GetMute(); } catch (Exception ex) { p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error"); p.outputStream.Write(ex.ToString()); return; } p.writeSuccess("text/plain"); p.outputStream.Write(muted ? "muted" : "unmuted"); } else if (p.requestedPage == "mousemove") { int dx = p.GetIntParam("dx"); // x change int dy = p.GetIntParam("dy"); // y change int delay = p.GetIntParam("delay").Clamp(1, 200); // Approximate milliseconds between movements. int times = p.GetIntParam("times").Clamp(1, 5000 / delay); // Number of times to perform the change. Limited to about 5 seconds of movement. try { DragMouse(dx, dy, delay, times); } catch (Exception ex) { p.writeSuccess("text/plain; charset=utf-8", responseCode: "500 Internal Server Error"); p.outputStream.Write(ex.ToString()); return; } p.writeSuccess("text/plain; charset=utf-8"); p.outputStream.Write("move complete. moved " + dx + "," + dy + " " + times + " times with " + delay + " ms delay"); } else if (p.requestedPage == "AllowLocalOverride") { Program.settings.syncAllowLocalOverride = true; Program.settings.Save(); p.writeSuccess("text/plain; charset=utf-8"); p.outputStream.Write("✅ Allow local input to override synced state"); } else if (p.requestedPage == "DisallowLocalOverride") { Program.settings.syncAllowLocalOverride = false; Program.settings.Save(); p.writeSuccess("text/plain; charset=utf-8"); p.outputStream.Write("❌ Allow local input to override synced state"); } else { successMessage = ""; } if (p.responseWritten) { return; } p.writeSuccess(additionalHeaders: additionalHeaders); p.outputStream.Write("<html><head><title>Monitor Control Service</title></head>" + "<style type=\"text/css\">" + " table { border-collapse: collapse; }" + " th, td { border: 1px solid black; padding: 3px 5px; }" + "</style>" + "<body>" + "<p class=\"result\">" + successMessage + "</p>" + "<p class=\"syncStatus\">(Remote server \"" + Program.settings.syncAddress + "\") " + HttpUtility.HtmlEncode(MonitorControlService.syncedServerStatus) + "</p>" + "<table>" //+ "<thead>" //+ "<tr><th></th><th></th></tr>" //+ "</thead>" + "<tbody>" + BuildRow("on", "turn displays on") + BuildRow("on?offAfterSecs=15", "turn displays on, then after 15 seconds, off") + BuildRow("cancel", "cancel a scheduled monitor off command (see above)") + BuildRow("off", "turn displays off") + BuildRow("off?ifidle=3000", "turn displays off if idle for 3000ms") + BuildRow("off?delay=3000&ifidle=2900", "wait 3000ms, then turn displays off if idle for 2900ms") + BuildRow("off?delay=3000&ifidle=2900&mute=1", "wait 3000ms, then turn displays off if idle for 2900ms, and also mute until the computer is no longer idle") + BuildRow("off_if_idle", "turn displays off if idle for the configured idle time (" + Program.settings.idleTimeMs + " ms)") + BuildRow("off_if_idle?mute=1", "turn displays off if idle for the configured idle time (" + Program.settings.idleTimeMs + " ms). Also mute until the computer is no longer idle.") + BuildRow("standby", "change displays to standby state -- probably does nothing") + BuildRow("status", "return the current status (\"on\" or \"off\")") + BuildRow("idle", "return the time in milliseconds since the last user input") + BuildRow("smarttoggle", "if status is \"on\" then <b>off_if_idle</b>, else <b>on</b>. Also supports the <b>mute</b> boolean argument.") + BuildRow("getvolume", "returns default audio device volume from 0 to 100") + BuildRow("setvolume?level=10", "sets default audio device volume from 0 to 100") + BuildRow("mute", "mutes default audio device") + BuildRow("unmute", "unmutes default audio device") + BuildRow("getmute", "returns \"muted\" or \"unmuted\"") + BuildRow("mousemove?dx=2&dy=-2&delay=4×=5", "moves the mouse cursor up 2px and to the right 2px, 5 times, waiting 4ms between each movement. Max delay 200ms. Max 5 seconds movement per command.") + BuildRow("AllowLocalOverride", "Enables the setting \"Allow local input to override synced state\"") + BuildRow("DisallowLocalOverride", "Disables the setting \"Allow local input to override synced state\"") + "</tbody>" + "</table>" + "</body>" + "</html>"); }
private void buttonDot_Click(object sender, EventArgs e) { //出错后只可清除 if (isError) { System.Media.SystemSounds.Beep.Play(); return; } //上次按的不是数字先输入0 if (typeLastInput != LastInput.number) buttonNumber0.PerformClick(); //最多可以有一个小数点 if (!isInputedDot) { //输入小数点 currentText += "."; //按了数字键 typeLastInput = LastInput.number; } else System.Media.SystemSounds.Beep.Play(); }
//等号 private void buttonEqual_Click(object sender, EventArgs e) { //出错后只可清除 if (isError) { System.Media.SystemSounds.Beep.Play(); return; } if (typeLastInput == LastInput.number) currentNumber = double.Parse(currentText); if (binaryNumber == null) { binaryNumber = currentNumber; if (binaryOperator != null) currentNumber = BinaryCalc(previousNumber); } else { if (binaryOperator != null) currentNumber = BinaryCalc(currentNumber); } previousInputs.Clear(); currentText = currentNumber.ToString(); //按了等号 typeLastInput = LastInput.unaryOperators; }
//清除当前 private void buttonClearentry_Click(object sender, EventArgs e) { if (isError) buttonClear.PerformClick(); if (typeLastInput == LastInput.unaryOperators && previousInputs.Count > 0) previousInputs.RemoveAt(previousInputs.Count - 1); currentText = "0"; currentNumber = 0; typeLastInput = LastInput.number; }
private void Update() { if (Input.GetAxisRaw("Horizontal") > 0) { if (m_lastInput != LastInput.Up) { if (m_changeButtonSound) { m_changeButtonSound.Play(); } m_currentChoiceIndex++; if (m_currentChoiceIndex >= m_infos.Count) { m_currentChoiceIndex = 0; } m_lastInput = LastInput.Up; } } else if (Input.GetAxisRaw("Horizontal") < 0) { if (m_lastInput != LastInput.Down) { if (m_changeButtonSound) { m_changeButtonSound.Play(); } m_currentChoiceIndex--; if (m_currentChoiceIndex < 0) { m_currentChoiceIndex = m_infos.Count - 1; } m_lastInput = LastInput.Down; } } else { m_lastInput = LastInput.Nothing; } if (Input.GetButtonDown("Submit") && !m_isExecuting) { if (m_validateButtonSound) { m_validateButtonSound.Play(); } m_isExecuting = true; Execute(); } if (!m_isExecuting) { for (int i = 0; i < m_infos.Count; i++) { m_infos[i].Renderer.sprite = i == m_currentChoiceIndex ? m_infos[i].HoverSprite : m_infos[i].DefaultSprite; } } }
//输入数字 private void buttonNumbers_Click(object sender, EventArgs e) { //出错后只可清除 if (isError) { System.Media.SystemSounds.Beep.Play(); return; } //按了非数字键再按数字键会输入一个新的数字 if (typeLastInput != LastInput.number) buttonClearentry.PerformClick(); //清除首位的0 if (currentText == "0") currentText = ""; //输入时最多可以有16个有效数字 int lengthLimit = 16; if (isInputedDot) ++lengthLimit; if (currentText.StartsWith("0.")) ++lengthLimit; if (currentText.Length < lengthLimit) currentText += (sender as Button).Text; else System.Media.SystemSounds.Beep.Play(); //按了数字键 typeLastInput = LastInput.number; }
//一元运算符(相反数 平方根 倒数 百分数) private void buttonUnaryOperators_Click(object sender, EventArgs e) { //出错后只可清除 if (isError) { System.Media.SystemSounds.Beep.Play(); return; } //输入数字取反特殊处理 if (typeLastInput == LastInput.number && sender == buttonInverse) { if (currentText.StartsWith("-")) currentText = currentText.Remove(0, 1); else currentText = "-" + currentText; } else { if (typeLastInput == LastInput.number) currentNumber = double.Parse(currentText); //操作number if (sender == buttonInverse) currentNumber = -currentNumber; else if (sender == buttonRadical) { if (currentNumber < 0) { currentText = "无效输入"; isError = true; } currentNumber = System.Math.Sqrt(currentNumber); } else if (sender == buttonReciprocal) { if (currentNumber == 0) { currentText = "除数不能为零"; isError = true; } currentNumber = 1 / currentNumber; } else if (sender == buttonPercent) currentNumber = previousNumber * currentNumber * 0.01; //更新表达式 if (typeLastInput == LastInput.unaryOperators && previousInputs.Count > 0) previousInputs.RemoveAt(previousInputs.Count - 1); previousInputs.Add(currentNumber.ToString()); currentText = currentNumber.ToString(); //按了一元运算符 typeLastInput = LastInput.unaryOperators; } }