C# Actively detect Lock keys

后端 未结 4 1231
我在风中等你
我在风中等你 2021-01-24 06:38

I have a wireless keyboard and mouse that doesn\'t have any lock indicators, nor any software bundled to provide a visual aid, so I\'m making my own.

I got it so that if

4条回答
  •  悲哀的现实
    2021-01-24 06:48

    Here is an example for intercepting the keyup on a form or something and tracking it. I changed a local variable, but you can just as easily trigger GUI updates at that time.

        private bool capLock;
        private bool numLock;
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.CapsLock)
            {
                capLock = !capLock;
            }
            if (e.KeyCode == Keys.NumLock)
            {
                numLock = !numLock;
            }
        }
    

提交回复
热议问题