Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using System. Runtime. InteropServices;
Namespace sn set keyboard case sensitivity
{Www.2cto.com
Public partial class Form1: Form
{
Const uint KEYEVENTF_EXTENDEDKEY = 0x1;
Const uint KEYEVENTF_KEYUP = 0x2;
[DllImport ("user32.dll")]
Static extern short GetKeyState (int foreign rtkey );
[DllImport ("user32.dll")]
Static extern void keybd_event (byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo );
Public enum VirtualKeys: byte
{
VK_NUMLOCK = 0x90, // number lock key
VK_SCROLL = 0x91, // scroll to lock
VK_CAPITAL = 0x14, // case-sensitive lock
VK_A = 62
}
Public Form1 ()
{
InitializeComponent ();
}
Public static bool GetState (VirtualKeys Key)
{
Return (GetKeyState (int) Key) = 1 );
}
Public static void SetState (VirtualKeys Key, bool State)
{
If (State! = GetState (Key ))
{
Keybd_event (byte) Key, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );
Keybd_event (byte) Key, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0 );
}
}
// Enable uppercase keyboard
Private void btnOpenCAPITAL_Click (object sender, EventArgs e)
{
SetState (VirtualKeys. VK_CAPITAL, true );
}
// Close the upper case of the keyboard
Private void btnCloseCAPITAL_Click (object sender, EventArgs e)
{
SetState (VirtualKeys. VK_CAPITAL, false );
}
// Enable keyboard scroll lock
Private void btnOpenScroll_Click (object sender, EventArgs e)
{
SetState (VirtualKeys. VK_SCROLL, true );
}
// Disable keyboard scroll lock
Private void btnCloseScroll_Click (object sender, EventArgs e)
{
SetState (VirtualKeys. VK_SCROLL, false );
}
// Enable the keyboard number lock key
Private void btnOpenNum_Click (object sender, EventArgs e)
{
SetState (VirtualKeys. VK_NUMLOCK, true );
}
// Disable the keyboard number lock key
Private void btnCloseNum_Click (object sender, EventArgs e)
{
SetState (VirtualKeys. VK_NUMLOCK, false );
}
}
}