利用API取得键盘状态

  [DllImport("USER32", SetLastError = true)]
  static extern short GetKeyState(int nVirtKey);
  const int VK_CONTROL = 0x11;

    int nVirtKey; 
    nVirtKey = GetKeyState(09) ;
    if(nVirtKey == -127||nVirtKey == -128)
    {
     btn3.Focus();
     e.Cancel=true;
    } 

你可能感兴趣的:(c#)