简体   繁体   中英

InputLanguage compatibility with win8 c#

I need my app input language always be Russian. The following code works fine on Win XP:

public void SetNewLanguage()
        {
            InputLanguage myCurrentLanguage = InputLanguage.FromCulture(Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU"));
            InputLanguage.CurrentInputLanguage = myCurrentLanguage;
        }

eg it sets input language to Russian whatever default language is (assuming that ru-RU culture is installed).

The issue is that calling the same function in Win 8.1 (where ru-RU installed as well) doesn't apply, so input language stays to be in English.

Any ideas how to get the code above working for XP and Win 8?

I'm not really a programmer, but I've been struggling with a similar issue, where my app was selecting the Spanish keyboard layout just fine in Windows 7, but not in the Windows 8.1 VM I've recently moved my VS to, and I appear to have it cracked.

It looks like it's because Windows 8.1 doesn't have per-application language switching enabled by default, because after I followed the instructions on https://superuser.com/questions/466180/set-windows-8-to-per-application-input-language-mode the original code worked.

However, this is what I found before I found that:

I originally had the code in program.cs, so that the app wouldn't finish launching if a Spanish keyboard layout wasn't available. If one was, it set it and finished starting up. While that works on Windows 7 (and sets the keyboard layout just for the one app), it seems Windows 8.1 doesn't do squit until the form's visible on the screen.

To get it to work in Windows 8, I had to stick in a Load event on the main form and set the keyboard layout in there:

private void Form1_Load(object sender, EventArgs e

What I would do is to try to get the keyboard layout of the system. It will help you determine what the language setting is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM