-1

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.

Deekay
  • 101
  • Is this something more along the lines of what you're asking for? https://stackoverflow.com/questions/26977904/short-press-and-long-press-handling You can create custom event handlers for key press events, and in those handlers introduce logic that controls how long held keys are handled. – emagers Apr 13 '22 at 16:48
  • `Hence, I was forced to asked my question again.` - you are actually supposed to edit your question and mark it for reopen, and two other need to review your edit and declare it reopen worthy aswell – Rand Random Apr 13 '22 at 16:53
  • @Rand Random I just followed the instructions: "Your post has been associated with a similar question. If this question doesn’t resolve your question, ask a new one.", and figured that editing a closed question wouldn't have any effect (as in: the question would stay closed). Thanks for the info. – Deekay Apr 13 '22 at 16:59
  • I could be wrong, that's how I would have handled it and how I learned it, but having two active questions, about the same topic seems wrong to me. (your other question also has fresh comments) – Rand Random Apr 13 '22 at 17:01
  • @Eric Magers not really, no. Suppose I have 6 programs open, each handling the keypress on their own, yet program 1+2 need to have a slow rate, 3,4 and 5 a medium and 6 a high rate, then if I change it in one program, only one of them handles the keypress as programmed. If I can alter the Windows setting, then it has an effect on all other programs. So if I set it to "medium" and switch from 3 to 4 or 5, I wouldn't have to change anything. But thanks for the effort! – Deekay Apr 13 '22 at 17:01
  • @Deekay I'm not sure I'm understanding your issue. The SO post gives you a way in which all applications can configure their own repeat rate. In your question you state that is what is desired because each application needs to have a different configured rate. Are you now saying that some applications should always have the same rate and that those rates should be kept in sync? If that's the case then you will likely need some external store for the configured rates per application that manages how theyre linked and some interface to configure those rates which each application can read from. – emagers Apr 13 '22 at 17:09
  • @Eric Magers You understand correctly. Suppose program 1 has a repeat rate of 10, 2 has one of 20 and 3 has one of 25. If I change the repeat rate to 15 in program 2, and then alt-tab to program 1, the repeat rate should also be 15 as set by the other program. So indeed, each program should check a common "store", which is only possible for self-written programs (which is the case at the moment, but will change). However, by changing the repeat rate in Windows, all programs share the same rate - I only need to find a way to do it from within the program, and not via Control Panel. Thanks. – Deekay Apr 13 '22 at 23:08
  • May I ask why you are this against the proposed P/Invoke solution? – Rand Random Apr 14 '22 at 16:31
  • @RandRandom Because it uses an external .dll. After working for 20 years as a software developer for a company where it's not allowed to use any kind of external .dll, it's become a bit of a habit, one I tend to stick by. – Deekay Apr 14 '22 at 16:39

1 Answers1

0

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

  • Windows only, fortunately. But this boils down to the same comment stuartd gave on the original question - using a .dll, which is not what I wanted. I'd like to be able to do it in C# without relying on an external .dll. If that is not possible, then I'll just have to live with opening the control panel each time I guess... – Deekay Apr 13 '22 at 23:11
  • Then I'm sorry there is no builtin functionallity to change the settings you want to change – Johannes Krackowizer Apr 14 '22 at 07:37