리눅스맨

how to turn on caps lock in c#

※ 위 배너를 클릭하면 1달러에 (900원~1800원) 살 수 있는 가성비 레어템 많습니다.

how to turn on caps lock in c#

 

1. Firstly add namespace and DllImport!!

 

using System.Runtime.InteropServices;

[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

 

2. Make a function with the code below.

private void capslock_on_off(string on_off = "on")
{
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;

//on
if (on_off.ToLower().Equals("on"))
{
if (Control.IsKeyLocked(Keys.CapsLock))
{

}
else
{
keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);
}
}
else
{
//off
if (Control.IsKeyLocked(Keys.CapsLock)) 
{
keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);
}
}

}

 

3. How to code using code!!

Invoke a function by putting lowercase and upper case options into the Enter, TextChanged event each respectively.

 capslock_on_off("off");

 

 


게시됨

카테고리

작성자

태그: