'How to change the keyboard repeat rate specifically in C#

Yesterday I posted the question below (see How to change the keyboard repeat rate in C#) but it was marked as duplicate and closed. However, I believe the question isn't a duplicate (I'm not asking how to change the keyboard repeat rate in general, I'm specifically asking for a way to handle it in C#), nor was it answered (the answers in the linked question, How can I increase the key repeat rate beyond the OS's limit?, are useless, and the code provided in a comment is neither C# nor readable enough to convert into C#). Hence, I was forced to asked my question again.

In short, the question was closed, but alas I have not received an answer.

My original question was: In Windows it is possible to change the keyboard repeat rate by going to the control panel, keyboard settings, and adjusting the slider for the keyboard repeat rate.

Because I need (very) different keyboard repeat rates in various self-written programs I'm using at the same time, I need to be able to quickly change the repeat rate.

Is there a way to do this programmatically in C#? This way, I could add a button in each of the programs to quickly set the ideal repeat rate for said software, without having to keep the control panel open.



Solution 1:[1]

Settings like this are OS specfic so there is no way to do it in c# for every OS. But for example in Windows you can at least read this settings SystemInformation.KeyboardSpeed Property

If you want to modify it you need to use the Win32 API SystemParametersInfoA function (winuser.h) Specificaly SPI_SETKEYBOARDDELAY

I would recommend PInvoke if you want to work with Win32 API.

If you are on Linux or Mac ... good luck

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Johannes Krackowizer