1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| protected static final Call LOAD_LAYOUT = new Call( "USER32.DLL", "LoadKeyboardLayoutA","GI:I",12);
protected static final Call ACTIVATE_LAYOUT = new Call( "USER32.DLL", "ActivateKeyboardLayoutA", "II:I:",8);
protected static final String INPUT_LOCAL = "00000401"; // langue d'entrée
protected static final int ACTIVE_PARAM = 0x00000001;
/**
* changer la langue d'entrée ( entrée clavier) du système
*/
public void loadInputLanguage() throws COMException, IOException {
FuncPtr loadLayout = null ;
FuncPtr activateLayout = null;
/**
* Charger la langue d'entrée
*/
loadLayout = new FuncPtr( LOAD_LAYOUT.getDllName(), LOAD_LAYOUT.getFunctionName());
NakedByteStream bs = new NakedByteStream();
LittleEndianOutputStream leo = new LittleEndianOutputStream
/**
* If the specified input locale identifier is not already loaded,
* the function loads and activates the input locale identifier for the current thread
*/
leo.writeStringUnicode( INPUT_LOCAL);// ( 0x1401) input arabic
leo.writeInt(ACTIVE_PARAM);
byte[] b = loadLayout.invoke( LOAD_LAYOUT.getParameterDescription(), LOAD_LAYOUT.getStackSize(), bs, null, ReturnFlags.CHECK_FALSE);
System.out.println(LOAD_LAYOUT.getStackSize());
LittleEndianInputStream leis = new LittleEndianInputStream( new ByteArrayInputStream( b));
int hkl = leis.readInt();
/**
* Activer la langue d'entrée chargée
*/
activateLayout = new FuncPtr( ACTIVATE_LAYOUT.getDllName(), ACTIVATE_LAYOUT.getFunctionName());
NakedByteStream bsa = new NakedByteStream();
LittleEndianOutputStream leoa = new LittleEndianOutputStream(bsa);
/**
* Activates the specified locale identifier for the entire process and sends
* the WM_INPUTLANGCHANGE message to the current thread's focus or active window
*/
//Input locale identifier to be activated.
leoa.writeInt(hkl);
leoa.writeInt( 0x00000100);
// KLF_SETFORPROCESS
byte[] ba = activateLayout.invoke( ACTIVATE_LAYOUT.getParameterDescription(), ACTIVATE_LAYOUT.getStackSize(), bsa, null, ReturnFlags.CHECK_FALSE);
LittleEndianInputStream leisa = new LittleEndianInputStream( new ByteArrayInputStream( ba));
int lastHkl = leisa.readInt();
if(lastHkl == 0) {
System. err.println( "Failed to activate keyboard layout");
}
loadLayout.close();
activateLayout.close();
} |
Partager