Baran Topal

Baran Topal


May 2024
M T W T F S S
« Feb    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories


capture 2 keys in C#.NET

baranbaran

Long ago, I needed to capture 2 keys, shift and F5 keys during debugging for C# in VS 2010 and the following code:

if(e.Shift && e.KeyCode == Keys.F5)

However, no matter how fast or slow I pressed, the above statement will not be true.

Since key events are received one at a time, if you pressed 10 keys at once they would be processed in a queue.

The correct approach shall be as follows:


if(e.Shift)
{
//set boolean to true
}

if(boolean==true)
{
if(e.KeyCode == Keys.F8)
{
//your code here
}