■ keybd_event API 함수를 사용해 SCROLL LOCK/NUM LOCK/CAPS LOCK 키를 토글하는 방법을 보여준다.
▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
using System; using System.Runtime.InteropServices; namespace TestProject { /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Import ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 키보드 이벤트 발생시키기 - keybd_event(virtualKey, scanCode, flag, extraInformationHandle) /// <summary> /// 키보드 이벤트 발생시키기 /// </summary> /// <param name="virtualKey">가상 키</param> /// <param name="scanCode">스캔 코드</param> /// <param name="flag">플래그</param> /// <param name="extraInformationHandle">부가 정보 핸들</param> [DllImport("user32")] private static extern void keybd_event(byte virtualKey, byte scanCode, uint flag, IntPtr extraInformationHandle); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// KEYEVENTF_EXTENDEDKEY /// </summary> private const uint KEYEVENTF_EXTENDEDKEY = 0x01; /// <summary> /// KEYEVENTF_KEYUP /// </summary> private const uint KEYEVENTF_KEYUP = 0x02; /// <summary> /// VK_SCROLL /// </summary> private const byte VK_SCROLL = 0x91; /// <summary> /// VK_NUMLOCK /// </summary> private const byte VK_NUMLOCK = 0x90; /// <summary> /// VK_CAPITAL /// </summary> private const byte VK_CAPITAL = 0x14; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> private static void Main() { uint keyDown = KEYEVENTF_EXTENDEDKEY; uint keyUp = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP; keybd_event(VK_NUMLOCK, (byte)0, keyDown, new IntPtr(0)); keybd_event(VK_NUMLOCK, (byte)0, keyUp , new IntPtr(0)); keybd_event(VK_CAPITAL, (byte)0, keyDown, new IntPtr(0)); keybd_event(VK_CAPITAL, (byte)0, keyUp , new IntPtr(0)); keybd_event(VK_SCROLL, (byte)0, keyDown, new IntPtr(0)); keybd_event(VK_SCROLL, (byte)0, keyUp , new IntPtr(0)); } #endregion } } |