Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

when we press a key and keep pressing it the keypress and keydown event continuously fires. Is there a way to let these fire only after a complete cycle ,eg keydown and then key up.

I would like the user not to be able press the key continuously rather would like the user have to press then release the key board to type a character !

so that following case do not occur eg : pppppppppppppppppppppppp when user presses 'p' for 1 sec.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
461 views
Welcome To Ask or Share your Answers For Others

1 Answer

Declare a boolean isKeyDown, in theKeyDown Event, set the boolean to true. In the KeyUp event, set the boolean to false.

This is sample code

bool isKeyDown=false;
public void control_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    if(isKeyDown)
      return;
    isKeyDown=true;
    // do what you want to do
}

public void control1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
   isKeyDown=false;
   // do you key up event, if any. 
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...