Skip to main content
gamedev.net
🔒 Locked

[.net] OnKeydown problem

Started by Hikaru Dec 16, 2005 at 10:58 AM 0 replies 350+ views
Original Post
Hikaru
Hikaru
Hi! I got a problem with the OnKeyDown event. The problem is that whenever I try to make my character move in one direction it stops in the beginning (for about 0.5s) before it starts moving. Is there anyway to solve this problem without implementing Directxinput? My code looks something like this: this.KeyDown += new KeyEventHandler(OnKeyDown); void OnKeyDown(object sender, KeyEventArgs e) { string strKeyPress = null; strKeyPress = e.KeyCode.ToString(); switch(strKeyPress.ToUpper()) { case "UP": up = true; break; case "DOWN": down = true; break; ..and so on... /Hikaru
DaWanderer
DaWanderer
Is the code that makes your character move in the KeyDown event handler? If so, the key repeat is going to kick in and you'll get that delay just like if you were holding down a key in a text box.

A better solution would be to just set the boolean values up, down, etc. to true or false like you have it in the KeyDown event, but then actually move the character in your main loop or in another thread (make sure you catch the KeyUp event to stop the movement by resetting the booleans).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.