I have a project with keydown event, but as every keypress, i click on the key and if i kip clicking it, it will wait a half second and start spam quickly the key. I need it to spam with no cool down, what can i do?
3 Answers
This is called the Keyboard Repeat Delay, and it's a system-wide property that can be set in the Keyboard section in the Control Panel. Alternately, you can set it via code, using the SystemParametersInfo
Win32 API function, setting the SPI_SETKEYBOARDDELAY
flag.
To call it from C#, you probably need to define a P/Invoke signature, but luckily someone on PInvoke.net has done this for us already.
Don't forget that you are setting a system-wide setting! This might require admin privileges, and in any case, you should play nice and return it to the original setting once you're done.

- 14,492
- 3
- 37
- 63
Instead of changing the system-wide settings and still have a delay of 250ms, you can watch keydown and keyup events for the same key (don't forget that a user can press multiple keys at once and release them in different order). Start a timer with required frequency on keydown, and stop it on the keyup, and set your previous keydown handler as a timer handler.

- 457
- 3
- 7
Try using Reactive Extensions and use one of the time-related operator such as Sample or Interval to achieve what you need here.
http://msdn.microsoft.com/en-us/data/gg577609
As an example (just as a guide, typed without VS)
Observable.FromEventPattern<KeyPressEventArgs>(this, "KeyPress").Sample(500).....

- 6,405
- 21
- 29