0

I have the following code which opens keyboard properties dialog when ever user clicks on a button:

Process proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.FileName = "main.cpl";
proc.StartInfo.Arguments = "keyboard";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
proc.Start();
proc.WaitForExit();
int keyBoardWindow;
while ((keyBoardWindow = FindWindow(null, "Keyboard Properties")) == 0) ;
int isSet = SetForegroundWindow(keyBoardWindow);

This code works fine when the default language of your system is English, in case of other languages like Chinese the FindWindow method doesn't exit. May be its because the dialog window does not have the name "Keyboard Properties" anymore. What do you people suggest? How should I handle this so that I am able to open keyboard properties dialog whatever the language of the system may be.

dymanoid
  • 14,771
  • 4
  • 36
  • 64
Sameed
  • 655
  • 1
  • 5
  • 18
  • 1
    Why do you want to search the window manually? You can just call `control.exe keyboard`, so the keyboard properties window will be automatically displayed as a foreground window. – dymanoid Sep 18 '17 at 16:23
  • @dymanoid, if I comment the last three lines , I am able to show the properties window in english language system, but the same thing doesnt work with chinese, the window doesnt show up, what do you think might be the problem. – Sameed Sep 18 '17 at 16:28
  • 1
    Just tested on a Japanese Win 7. `control.exe keyboard` works just fine. Use it instead of `main.cpl`. – dymanoid Sep 18 '17 at 16:33
  • @dymanoid, Thanks man, it worked. Write a short answer i'll accept it, even tough we dont know the reason what was the problem with main.cpl, it works fine for mouse properties both in english and chinese. – Sameed Sep 18 '17 at 16:39

1 Answers1

1

As described in MSDN, you should open the Control Panel's Keyboard properties window using this command:

control.exe keyboard

You can find another commands there, such as mouse or fonts settings.

dymanoid
  • 14,771
  • 4
  • 36
  • 64