首页 文章资讯内容详情

通过C#中的控制台检查Caps Lock和Num Lock是否打开或关闭

2026-06-05 1 花语

要通过控制台检查CapsLock是打开还是关闭,代码如下-

示例

using System; public class Demo{ public static void Main(string[] args){ Console.WriteLine("The CAPS LOCK is on or not? "+ Console.CapsLock); } }

输出结果

这将产生以下输出-

The CAPS LOCK is on or not? False

示例

要通过控制台检查NumLock是打开还是关闭,代码如下-

using System; public class Demo{ public static void Main(string[] args){ Console.WriteLine("The Num LOCK is on or not? "+ Console.NumberLock); } }

输出结果

这将产生以下输出-

The Num LOCK is on or not? True