0

There are number of keyboards in US English alone. How to know which keyboard layout the user is using now? Particularly whether he is using US International Keyboard or not. I have tried with,

private void TextServiceManager_InputLanguageChanged(CoreTextServicesManager sender, object args){        
Debug.WriteLine(GetCurrentCultureInfo().AllProperties + " " +
sender.InputLanguage.DisplayName + " " +
sender.InputLanguage.LanguageTag + "  " +
sender.InputLanguage.Script + "  " +
sender.InputLanguage.NativeName);}

But could not get that!

Mg Bhadurudeen
  • 1,140
  • 1
  • 12
  • 24
  • Perhaps this will help? https://stackoverflow.com/questions/27747176/detect-current-keyboard-language-layout-name-in-multi-language-computer – Adam Jul 16 '18 at 17:07
  • What is it you are trying to do? Why do you need to know the current keyboard layout? – Neil Jul 16 '18 at 17:39
  • @Adam, I already saw that, and tried to get KeyboardLayoutId, but that does not seem to be available in uwp. So looking for a workaround if any. – Mg Bhadurudeen Jul 16 '18 at 17:40
  • @Neil, I am developing an app which should detect the keyboard layout and direct/warn user for languages other than English, ie.. for Spanish, Portuguese and few more. They could be achieved through US International kb easily with same kb for all. – Mg Bhadurudeen Jul 16 '18 at 17:43
  • I still don't understand why this is a problem. Are there keys that are required for your app that don't exist on a Spanish keyboard? – Neil Jul 16 '18 at 17:47
  • @Neil, All Spanish characters exists in a Spanish keyboard, no doubt. But the problem is, if I direct user to use Spanish keyboard, he should press forward slash to type hyphen. Number of characters are different than printed on the normal physical keyboard. It will confuse the user. This issue not arises with US International keyboard. Another requirement is, It would be easy to direct users to use US International kb, whatever the language they choose, instead of selecting different for different languages. – Mg Bhadurudeen Jul 16 '18 at 17:55
  • I think you are trying to solve a problem that either doesn't exist, or you are thinking there is a problem when there isn't. A Spanish keyboard already has a hyphen key, so why would they need to press slash? If your application requires non-standard keys, then you should change your application to use keys that appear on all keyboards. If you need special keys, potentially, they won't appear on a US keyboard ! – Neil Jul 16 '18 at 20:24
  • @Neil, No! it is mis-understood. This (https://d25rq8gxcq0p71.cloudfront.net/language-guide/758/es-keyboard.jpg) is the layout of Spanish keyboard: Right? The hyphen is present left to the Right shift key in this virtual keyboard. But in physical keyboard (that all of us use with our pc), we see can the Forward Slash at this place. So user has to remember, that he has to press forward slash in physical kb(not virtual) to get the hypen when he is typing in spanish. The case is entirely different when typing in Portuguese. – Mg Bhadurudeen Jul 17 '18 at 02:43
  • @Neil, For this purpose alone, amazon sells keyboard sticker for spanish, portugues etc. To avoid these like situations, the US International keyboard is used! Except special accents, all remain same for all languages (http://www.techlanguage.com/tips/us_international.html). – Mg Bhadurudeen Jul 17 '18 at 02:44
  • 1
    There's no such API for you to detect current keyboard. You could submit a 'Feature Request' on [WPDev UserVoice](http://wpdev.uservoice.com/). – Xie Steven Jul 17 '18 at 08:19
  • This physical keyboard https://www.datacal.com/p-261-spanish-keyboard.aspx matches the virtual one. Are you saying that Spanish developers do not have access to the slash character? I can see on that picture both \ and /. I still think you think there is a problem when there isn't one. – Neil Jul 17 '18 at 09:43
  • The user has chosen to set a keyboard layout. If that layout doesn't match what's printed on their keys, that's presumably a choice that the user has been happy to make (especially if they touch type and so the labels on the keyboard matter not a jot, just what layout they want to use). – Damien_The_Unbeliever Jul 17 '18 at 10:01
  • If I explain the real scenario, you will agree with me. This is a Typing App which helps to type in English, Spanish, Portuguese, German. I will show characters of those languages in the App and user has to press those characters displayed on the screen. If they see forward slash, in any language, they will press the right most key in lower row of the keyboard, If it is international kb. Would it not be the right choice? If corresponding language keyboard used, then he has to memorize 4 different keys for a single character "/". I hope, this will not be a better way for this scenario. – Mg Bhadurudeen Jul 17 '18 at 11:30

2 Answers2

0

You can use this API to get the current keyboard layout (P/Invoke version), which will tell you which keyboard layout the user has selected. This may not be the same as the physical keyboard connected.

Neil
  • 11,059
  • 3
  • 31
  • 56
  • Is it for uwp? I thought it was for (non uwp) desktop apps only. – Mg Bhadurudeen Jul 17 '18 at 10:33
  • Can UWP not call Win32/PInvoke functions? This page (https://learn.microsoft.com/en-us/uwp/win32-and-com/win32-and-com-for-uwp-apps) suggests you should be able to do it via C++/CX, so if you can't call it directly, a simple managed C++ assembly should work. – Neil Jul 17 '18 at 10:40
  • I suspected this code at first. but it really worked! This is amazing.... Those who downvoted, please upvote this answer. – Mg Bhadurudeen Jul 21 '18 at 16:43
0
string StrCurrentLang = InputLanguage.CurrentInputLanguage.Culture.TwoLetterISOLanguageName;

up line code get you two last letter sign of current language

on the other side you can change current language by using down paragraph code

    foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages)
    {

        if (lang.Culture.TwoLetterISOLanguageName != "us")
        {
            InputLanguage.CurrentInputLanguage = lang;
            return;
        }
    }
Esi
  • 389
  • 5
  • 14