计时器取决于封套

timer depends on capslock

本文关键字:取决于 计时器      更新时间:2023-10-16

我使用visual studio 2010 c++,正在制作一个Windows窗体应用程序。我的问题是我如何做一个定时器,将启动和停止取决于capslock状态,就像它会开始时,capslock是打开和关闭时停止。就像这样

public void keyDownEvent(... )
    {
       if (capslockOn != 0)
           timer1->enabled = true
       else
           timer1->enabled = false
    }

在c++中,你可以使用Windows API函数GetKeyState来确定CAPS LOCK键的状态:

SHORT WINAPI GetKeyState(
  _In_  int nVirtKey
);
测试:

if ((GetKeyState(VK_CAPITAL) & 0x0001)!=0)
  // Caps Lock is ON
else
  // Caps Lock is OFF

,其中VK_CAPITAL为0x14。低阶位打开或关闭,指示密钥的状态。