ConsoleKeyDispatcher 2.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ConsoleKeyDispatcher --version 2.0.0
NuGet\Install-Package ConsoleKeyDispatcher -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ConsoleKeyDispatcher" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConsoleKeyDispatcher" Version="2.0.0" />
<PackageReference Include="ConsoleKeyDispatcher" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ConsoleKeyDispatcher --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ConsoleKeyDispatcher, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ConsoleKeyDispatcher@2.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ConsoleKeyDispatcher&version=2.0.0
#tool nuget:?package=ConsoleKeyDispatcher&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ConsoleKeyDispatcher
ConsoleKeyDispatcher는 콘솔 애플리케이션에서 키 입력에 따라 다양한 액션(동기/비동기 핸들러)을 손쉽게 등록하고 실행할 수 있도록 도와주는 도구입니다.
주요 기능
- 특정 키에 동기/비동기 핸들러 등록
- 등록된 핸들러 이름 및 키 목록 조회
- ESC(기본) 또는 지정한 키로 종료
- 키 입력이 있을 때만 핸들러 실행 또는 무한 디스패칭 루프 지원
사용 예시
아래는 Example 프로젝트의 간단한 사용 예시입니다.
시작하기
ConsoleKeyDispatcher.BindHandler또는ConsoleKeyDispatcher.BindAsyncHandler로 키와 핸들러를 등록합니다.ConsoleKeyDispatcher.BindExitHandler로 종료 키를 등록합니다(기본 ESC).ConsoleKeyDispatcher.KeepDispatching()을 호출하여 입력을 처리합니다.
예제 코드
ConsoleKeyDispatcher.BindHandler(ConsoleKey.H, () =>
{
foreach ((ConsoleKey key, string? name) in ConsoleKeyDispatcher.HandlerNames)
{
Console.WriteLine($"Handler: {key} | {name ?? "No Name"}");
}
}, "Help");
ConsoleKeyDispatcher.KeyNotRegistered += (sender, e) =>
{
Console.WriteLine($"Key '{e.Key}' is not registered. Press 'H' for help.");
};
ConsoleKeyDispatcher.BindExitHandler();
ConsoleKeyDispatcher.BindHandler(ConsoleKey.A, () => Console.WriteLine("Hello, World!"), "Print Hello, World!");
ConsoleKeyDispatcher.BindHandler(ConsoleKey.B, () => Console.WriteLine(DateTime.Now), "Print DateTime.Now");
ConsoleKeyDispatcher.BindAsyncHandler(ConsoleKey.C, async () =>
{
await Task.Delay(1000);
Console.WriteLine("Async operation completed after 1 second.");
}, "Async Operation");
Console.WriteLine("Press 'H' for help. Press 'Escape' to exit.");
ConsoleKeyDispatcher.KeepDispatching();
라이선스
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.