using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; //Added
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
public static extern short GetKeyState(int keyCode);
private void button1_Click(object sender, EventArgs e)
{
bool CapsLock = (((ushort)GetKeyState(0x14)) & 0xffff) != 0;
bool NumLock = (((ushort)GetKeyState(0x90)) & 0xffff) != 0;
bool ScrollLock=(((ushort)GetKeyState(0x91))&0xffff)!=0 ;
MessageBox.Show("Caps Lock is: " + CapsLock.ToString() + "\n" + "Num Lock is: " + NumLock.ToString() + "\n" + "Scrol lLock is: " + ScrollLock.ToString());
}
}
}