0

This is basically a simple question.

I want to update the label dynamically when I press the capslock and numlock keys while the main form is open in the WinForm application on the .net platform. How can I do this?

ɢʀᴜɴᴛ
  • 32,025
  • 15
  • 116
  • 110
  • 3
    possible duplicate of https://stackoverflow.com/questions/17683620/c-sharp-actively-detect-lock-keys and https://stackoverflow.com/questions/577411/how-can-i-find-the-state-of-numlock-capslock-and-scrolllock-in-net – jason.kaisersmith Aug 10 '17 at 08:44

1 Answers1

0

You have to listen for keypress callbacks like that

private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
    if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
    {
        Keys k = (Keys)Marshal.ReadInt32(lParam);
        if (k == Keys.Capital)
        {
            label1.Text = "Heureka";
        }
    }
    return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
kocica
  • 6,412
  • 2
  • 14
  • 35