MOIS keyboard

yan007

09-07-2010 11:45:39

Is it possible to let MOIS pick the type of keyboard (azerty <-> qwerty) from the underlying OS?
default it's qwerty but I can't find how to change this (manually or automatically)?

Beauty

26-07-2010 13:08:42

Maybe you can find it out by a .NET library?
..... search on web or ask in a C# forum

Or alternatively by SlimDX? (You need to include the slimdx.dll file to your project.)

mstoyke

26-07-2010 14:24:54

Hi,

this code will not work out of the box, it's just some old code snippet I found in my repository that I used some years ago to convert DirectX scancodes into localized ASCII codes through the system keyboard layout.
This code snipper might help you to get the right idea where to look for the answer.


//////////////////////////////////////////////////////////////////////////
[DllImport( "user32.dll" )]
internal static extern bool GetKeyboardState( byte [] keyState );

//////////////////////////////////////////////////////////////////////////
[DllImport( "user32.dll" )]
private static extern int MapVirtualKeyW( int code, int mapType );

//////////////////////////////////////////////////////////////////////////
[DllImport( "user32.dll", CharSet = CharSet.Unicode )]
private static extern int ToUnicode( int virtKey, int scanCode, byte [] keyState,
StringBuilder buff, int buffs, uint flags );

/************************************************************************/
/* */
/************************************************************************/
internal static string ConvertSCToUnicode( KeyCodes _scanCode, KeyModifiers _mod )
{
byte [] keyState = new byte [ 256 ];
GetKeyboardState( keyState );

if( ( _mod & KeyModifiers.Shift ) > KeyModifiers.None )
keyState [ 16 ] = 128;
if( ( _mod & KeyModifiers.Ctrl ) > KeyModifiers.None )
keyState [ 17 ] = 128;
if( ( _mod & KeyModifiers.Alt ) > KeyModifiers.None )
keyState [ 18 ] = 128;
if( ( _mod & KeyModifiers.RAlt ) > KeyModifiers.None ) // keyState[18] is already set through
keyState [ 17 ] = 128;

int scanCode = (int) _scanCode;
int vk = MapVirtualKeyW( scanCode, 1 );
if( vk != 0 )
{
StringBuilder sb = new StringBuilder();

int rc = ToUnicode( vk, scanCode, keyState, sb, sb.Capacity, 0 );

if( rc == 1 )
{
return sb.ToString();
}
}

return string.Empty;
}