在C#/ Windows窗体中检测应用程序启动时的Shift键

问题描述:

有没有办法让标准的Windows Forms应用程序检测在应用程序启动时是否按住Shift键 - 而不使用Windows挂钩?在C#/ Windows窗体中检测应用程序启动时的Shift键

理想情况下,如果在EXE文件运行时按住Shift键,工作流程将从正常状态改变。

Here is an article关于直接读取关键状态(和鼠标)。

检查Control.ModifierKeys ...

[STAThread] 
    static void Main(string[] args) 
    { 
     if (Control.ModifierKeys == Keys.ShiftKey) 
     { 
      // Do something special 
     } 
    } 
+0

任何关心解释他们为什么低估了我的答案? – 2009-06-09 11:46:54

的ModifierKeys属性看起来理想:

private void Form1_Load(object sender, EventArgs e) 
{ 
    if ((ModifierKeys & Keys.Shift) != 0) 
    { 
     MessageBox.Show("Shift is pressed"); 
    } 
} 

我知道这个帖子是相当老了,但我遇到了这个问题,并通过修改固定它杰米代码:

[STAThread] 
static void Main(string[] args) 
{ 
    if (Control.ModifierKeys.ToString() == "Shift") 
    { 
     // Do something special 
    } 
}