private void SetStatus() { this.notifyIconNUM.Visible = showNumLock; this.notifyIconCAPS.Visible = showCapsLock; if (showNumLock) { if (KeyboardIndicator.GetKeyState(NUM_KEYCODE) != 0) { this.notifyIconNUM.Icon = Resources.NumLockOpen; this.notifyIconNUM.Text = "NumLock On"; } else { this.notifyIconNUM.Icon = Resources.NumLockClose; this.notifyIconNUM.Text = "NumLock Off"; } } if (showCapsLock) { if (KeyboardIndicator.GetKeyState(CAPS_KEYCODE) != 0) { this.notifyIconCAPS.Icon = Resources.CapsLockOpen; this.notifyIconCAPS.Text = "CapsLock On"; } else { this.notifyIconCAPS.Icon = Resources.CapsLockClose; this.notifyIconCAPS.Text = "CapsLock Off"; } } }
public KeyboardIndicator() { InitializeComponent(); try { showNumLock = ConfigurationManager.AppSettings["NumLock"].ToUpper() == "Y"; } catch (Exception) { showNumLock = false; } try { showCapsLock = ConfigurationManager.AppSettings["CapsLock"].ToUpper() == "Y"; } catch (Exception) { showCapsLock = false; } if (!showNumLock && !showCapsLock) { showNumLock = true; } this.SetStatus(); this.gHookProc = new KeyboardIndicator.HookProc(this.KeyBoardHookProc); KeyboardIndicator.SetWindowsHookEx(WH_KEYBOARD_LL, this.gHookProc, IntPtr.Zero, 0); }
static void Main() { bool flag; using (new Mutex(true, "KeyboardIndicator", out flag)) { if (flag) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form myform = new KeyboardIndicator(); Application.Run(); } } }