Bind multiple keys to KeyDown event (Shift + * (As

2019-06-10 03:30发布

I am trying to bind multiple keys on a KeyDown event to change a bool variable, but I can't seem to figure out how to trigger the asterisk/star key (*) with the Left Shift key in the following code:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (keyData == Keys.Multiply || keyData == (Keys.LShiftKey | Keys.OemQuotes))
    {
        Valgt = true;
    }
}

1条回答
劳资没心,怎么记你
2楼-- · 2019-06-10 04:03

This answer will not be keyboard layout invariant but this would do the trick on a US-EN keyboard. It's not robust but can be adapted to your local layout.

if (keyData == Keys.Multiply || keyData == (Keys.Shift | Keys.D8))
{
    Valgt = true;
}

Alternatively you can use Control_KeyPress event

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{            
    if (e.KeyChar == '*')
    {
        Valgt = true;
    }
}
查看更多
登录 后发表回答