Baran Topal

Baran Topal


April 2024
M T W T F S S
« Feb    
1234567
891011121314
15161718192021
22232425262728
2930  

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
}