在winforms中检测Shift + LWin +左键组合

时间:2018-01-19 20:47:59

标签: c# winforms keyboard-shortcuts

在Windows窗体上,如何检测Shift + LWin + Left键的组合?

我在表单上尝试了以下内容(使用KeyPreview = true)但没有成功。

    private void frmPlaceholderRectangle_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Modifiers == Keys.Shift && (e.KeyCode == (Keys.Left | Keys.LWin)))
        {
            //Do Something
            return;
        }
    }

1 个答案:

答案 0 :(得分:0)

这是一个足够的临时解决方法:

    private bool _ShiftWin = false;

    private void frmPlaceholderRectangle_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Modifiers == Keys.Shift && e.KeyCode == Keys.LWin)
        {
            _ShiftWin = true;
            txtShowName.Text = "Shift+Win Down at " + DateTime.Now.ToString();
        }
    }

    private void frmPlaceholderRectangle_KeyUp(object sender, KeyEventArgs e)
    {
        if (_ShiftWin && e.KeyCode == Keys.Left)
        {
            txtShowName.Text = "Left Key Up at " + DateTime.Now.ToString();
        }
        if (_ShiftWin && e.KeyCode == Keys.LWin)
        {
            txtShowName.Text = "Shift+Win Up at " + DateTime.Now.ToString();
            _ShiftWin = false;
        }
    }