简体   繁体   中英

Constant update of the form's data

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?

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM