Reputation: 5424
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;
}
}
Upvotes: 1
Views: 4409
Reputation: 1269
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;
}
}
Upvotes: 2