localization - SHIFT Shortcut being displayed as MAJ for culture "nl-BE" when it should be SHIFT (C#.NET) -


after long discussion infragistics appears shortcuts shift displayed maj in culture "nl-be". first of all, culture "nl-be" , azerty of strange thing. read http://en.wikipedia.org/wiki/azerty if want know more. important quote is:

the other keys identical, though traditionally names of special keys printed on them in english. because belgium predominantly bilingual (french-dutch) , officially trilingual (a third language, german, spoken in east cantons).

so maj printed shift. in office instance, shortcuts shift displayed shift. in infragistics controls displayed maj. , frustrates our customers.

so, after discussion infragistics claim it's windows api call returning maj instead of shift. have gotten sample project them shows behavior. question why windows api call doesn't return shift, , if it's normal, how office display correct?

the code text of key :

nativewindowmethods.getkeynametext((int)scancode, sb, 256); 

and

class nativewindowmethods {     #region mapvirtualkey     [dllimport("user32.dll")]     internal static extern int mapvirtualkey(uint ucode, uint umaptype);     #endregion //mapvirtualkey      #region getkeynametext     [dllimport("user32.dll", charset = charset.auto)]     internal static extern int getkeynametext(         int lparam,          [marshalas(unmanagedtype.lpwstr), out]system.text.stringbuilder str,          int size);     #endregion //getkeynametext } 

in case of shiftkey, scancode 2752512 (2a) , maj returned.

so, questions?

  • is normal maj returned culture "nl-be"? or bug in user32.dll?
  • if office gets right, isn't infragistics right?
  • does infragistics use correct user32.dll api call?

for completeness i'll paste full code utilities class. form next call done:

systemlocalizedstring = utilities.getlocalizedshortcutstring(shortcut);

with shortcut = shiftf12. after call, systemlocalizedstring equal "maj+f12".

update: of hans passant downloaded microsoft keyboard layout creator , exported current keyboard layout. in .klc file there's no maj found, shift (2a shift instance). why user32.dll return maj? weirder when make copy of .klc file , install new keyboard, user32.dll return shift newly installed keyboard (while it's exact copy).

utilities.cs:

using system; using system.collections.generic; using system.linq; using system.text; using system.windows.forms; using system.runtime.interopservices;  namespace windowsformsapplication1 {     class utilities     {          #region getlocalizedshortcutstring          /// <summary>         /// returns localized string specified <b>shortcut</b>         /// </summary>         /// <param name="shortcut">shortcut localize</param>         /// <param name="separator">character used separate multiple keys in shortcut</param>         /// <returns>a string containing localized description of shortcut based on mapped keyboard layout</returns>         public static string getlocalizedshortcutstring(shortcut shortcut, char separator = '+')         {             if (shortcut == shortcut.none)                 return string.empty;              return getlocalizedkeystring((keys)shortcut, separator);         }         #endregion //getlocalizedshortcutstring          #region getlocalizedkeystring          /// <summary>         /// returns localized string specified <b>keys</b>         /// </summary>         /// <param name="keys">keys localize</param>         /// <param name="separator">character used separate multiple keys</param>         /// <returns>a string containing localized description of keys based on mapped keyboard layout</returns>         public static string getlocalizedkeystring(keys keys, char separator)         {             bool alt = ((long)keys & (long)keys.alt) != 0;             bool ctrl = ((long)keys & (long)keys.control) != 0;             bool shift = ((long)keys & (long)keys.shift) != 0;              // key involved             long value = (long)keys & 0xffff;              keys key = (keys)enum.toobject(typeof(keys), value);             system.text.stringbuilder sb = new system.text.stringbuilder();              if (alt && key != keys.menu)             {                 sb.append(getlocalizedkeystringhelper(keys.menu));                 sb.append(separator);             }              if (ctrl && key != keys.controlkey)             {                 sb.append(getlocalizedkeystringhelper(keys.controlkey));                 sb.append(separator);             }              if (shift && key != keys.shiftkey)             {                 sb.append(getlocalizedkeystringhelper(keys.shiftkey));                 sb.append(separator);             }              sb.append(getlocalizedkeystringhelper(key));             return sb.tostring();         }         #endregion //getlocalizedkeystring          #region getlocalizedkeystringhelper         private static string getlocalizedkeystringhelper(keys key)         {             string localizedkey = getlocalizedkeystringunsafe(key);              if (localizedkey == null || localizedkey.length == 0)                 return key.tostring();              return localizedkey;         }         #endregion //getlocalizedkeystringhelper          #region getlocalizedkeystringunsafe         private static string getlocalizedkeystringunsafe(keys key)         {             // strip modifier keys             long keycode = ((int)key) & 0xffff;              system.text.stringbuilder sb = new system.text.stringbuilder(256);              long scancode = nativewindowmethods.mapvirtualkey((uint)keycode, (uint)0);              // shift scancode high word             scancode = (scancode << 16);              if (keycode == 45 ||                 keycode == 46 ||                 keycode == 144 ||                 (33 <= keycode && keycode <= 40))             {                 // add extended key flag                 scancode |= 0x1000000;             }              nativewindowmethods.getkeynametext((int)scancode, sb, 256);             return sb.tostring();         }         #endregion //getlocalizedkeystringunsafe     }      class nativewindowmethods     {         #region mapvirtualkey         [dllimport("user32.dll")]         internal static extern int mapvirtualkey(uint ucode, uint umaptype);         #endregion //mapvirtualkey          #region getkeynametext         [dllimport("user32.dll", charset = charset.auto)]         internal static extern int getkeynametext(int lparam, [marshalas(unmanagedtype.lpwstr), out]system.text.stringbuilder str, int size);         #endregion //getkeynametext     } } 

but using azerty, that's used in schools learn how type so...

so yes, that's problem. way can azerty layout select keyboard layout titled "français (belgique)" in control panel + language + add language. opposed "nederlands (belgië)" layout, has qwerty arrangement. getkeynametext() winapi function returns strings encoded in keyboard layout file. of course in french keyboard layout named français maj expected result. windows not have keyboard layout available speaks dutch azerty arrangement.

all not lost, windows users ask custom keyboard layouts. microsoft made tool available create own, microsoft keyboard layout creator. designed re-arrange keys, little elbow grease required make want. tool doesn't let directly edit key descriptions , defaults english names. you'll want start file + load existing keyboard. file + save layout save layout .klc file. open in text editor, notepad fine, locate sections named keyname , keyname_ext , edit key names way want them.

restart utility (don't skip) , reload .klc file. , build setup package project + build dll.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -