ภาพรวม
คุณสมบัติ Console.CapsLock และ Console.NumberLock คืนสถานะปุ่มกด (true = กดเปิด, false = ปิด)
ตัวอย่าง 1: Caps Lock
using System;
public class Demo {
public static void Main(string[] args) {
Console.WriteLine("The CAPS LOCK is on or not? " + Console.CapsLock);
}
}
ผลลัพธ์ตัวอย่าง 1
The CAPS LOCK is on or not? False
ตัวอย่าง 2: Num Lock
using System;
public class Demo {
public static void Main(string[] args) {
Console.WriteLine("The Num LOCK is on or not? " + Console.NumberLock);
}
}
ผลลัพธ์ตัวอย่าง 2
The Num LOCK is on or not? True
สรุป
- อ่านสถานะคีย์บอร์ดระดับระบบปฏิบัติการ
- ใช้ได้เฉพาะแอปพลิเคชันคอนโซลที่รันโต้ตอบกับคอนโซลจริง
- อาจไม่ทำงานในบางสภาพแวดล้อม (เช่น IDE output window)