From b855a18a432eea641ad2901bb013e5adba6b98da Mon Sep 17 00:00:00 2001 From: muqing <1966944300@qq.com> Date: Sun, 12 Jan 2025 17:26:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8E=A7=E5=88=B6=E5=8F=B0?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A8=A1=E5=BC=8F=E7=9A=84=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E8=B0=83=E6=95=B4=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E6=81=A2=E5=A4=8D=E6=97=B6=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ModelingMusic/MusicFrom.cs | 48 +++++++++++++++++++++----------------- Program.cs | 3 +-- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/ModelingMusic/MusicFrom.cs b/ModelingMusic/MusicFrom.cs index cfa47a7..b4bd383 100644 --- a/ModelingMusic/MusicFrom.cs +++ b/ModelingMusic/MusicFrom.cs @@ -38,30 +38,17 @@ public class MusicFrom public MusicFrom() { - // 获取标准输入句柄 - IntPtr hStdin = GetStdHandle(STD_INPUT_HANDLE); - - // 获取当前控制台输入模式 - uint mode; - if (!GetConsoleMode(hStdin, out mode)) - { - Console.WriteLine("无法获取控制台输入模式"); - return; - } - - // 禁用回显和行输入 - mode &= ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT); - if (!SetConsoleMode(hStdin, mode)) - { - Console.WriteLine("无法设置控制台输入模式"); - return; - } setCharArry(); MaxY = Program.chars.GetLength(0); MaxX = Program.chars.GetLength(1); new Thread(PrintCharArray).Start(); new Thread(KeyboardMapping).Start(); new Thread(Run).Start(); + + // 恢复控制台输入模式 + // mode |= ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT; + // SetConsoleMode(hStdin, mode); + } public void Run() @@ -127,6 +114,24 @@ public class MusicFrom public void PrintCharArray() { + // 获取标准输入句柄 + IntPtr hStdin = GetStdHandle(STD_INPUT_HANDLE); + + // 获取当前控制台输入模式 + uint mode; + if (!GetConsoleMode(hStdin, out mode)) + { + Console.WriteLine("无法获取控制台输入模式"); + return; + } + + // 禁用回显和行输入 + mode &= ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT); + if (!SetConsoleMode(hStdin, mode)) + { + Console.WriteLine("无法设置控制台输入模式"); + return; + } var stopwatch = new Stopwatch(); int frameCount = 0; double totalTime = 0; @@ -135,7 +140,6 @@ public class MusicFrom var a = Program.chars.GetLength(0); var b = Program.chars.GetLength(1); var buffer = new StringBuilder(); - ConsoleColor xiantiaoColor = Program.random.Next(0, 2) == 0 ? ConsoleColor.Red : ConsoleColor.Blue;//线条的颜色 while (Program.IsWhile) { stopwatch.Restart(); @@ -146,9 +150,6 @@ public class MusicFrom { for (j = 0; j < b; j++) { - //Console.ForegroundColor = Program.chars[i, j].Color; - //Console.Write($" {Program.chars[i, j].Char} "); - buffer.Append(Program.chars[i, j].Char); time++; if (time > 100000) @@ -225,6 +226,9 @@ public class MusicFrom //这样闪烁不会太严重 Thread.Sleep(50); } + // 恢复控制台输入模式 + mode |= ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT; + SetConsoleMode(hStdin, mode); } private void setCharArry() { diff --git a/Program.cs b/Program.cs index e29f603..47d3ef8 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,4 @@ -using System.Runtime.InteropServices; -using System.Text; +using System.Text; using Debug.ModelingMusic; namespace Debug; ///