Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes and no: yggdraa's code of Mar 13 worked fine on Windows but failed on Linux.</p> <p>There may be no universal solution for Linux at all: no such things as Windows' GetKeyboardLayout() and ActivateKeyboardLayout() there. Some configuration-dependent hacks might be possible though, such as parsing the output of xset (<a href="http://forums.debian.net/viewtopic.php?f=6&amp;t=82235" rel="nofollow">details here</a>) and forcing the layout, say, on key up/down.</p> <p>In the example above, the input selection code in eventDispatched() gets called too late - when the OS keyboard has already switched back to the system-default US.</p> <p>A few brute force attempts didn't work either: myParticularJField.setLocale(myForcedLocale) from the field's focus handler gets immediately undone upon the first key press. Same for forcing the top-level (JFrame/JDialog) Locale.</p> <p>Update:</p> <p>We have only Windows in production, so making this work under Linux is impractical: too much effort.</p> <p>Just in case, a byproduct. This correctly determines which layout is currently active: default or alternative ("local"). It can't distinguish among several alternative layouts:</p> <pre><code>import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class LinuxKeyboardLayoutStatus { public enum LayoutType { DEFAULT, LOCAL } public LinuxKeyboardLayoutStatus.LayoutType getCurrentKeyboardLayoutType() throws IOException, InterruptedException { String[] command = createCommand(); Process p = Runtime.getRuntime().exec(command); BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); String l = r.readLine(); r.close(); p.waitFor(); return decodeLayoutType(l); } protected String[] createCommand() { return new String[] { "/bin/sh", "-c", "xset -q | grep LED | awk '{ print $10 }' | cut -c5" }; } protected LinuxKeyboardLayoutStatus.LayoutType decodeLayoutType(String commandOutput) { return commandOutput != null &amp;&amp; !commandOutput.equals("0") ? LayoutType.LOCAL : LayoutType.DEFAULT; } } </code></pre> <p>Update:</p> <p>In Ubuntu, the change back to the default layout happens at the X window level (DBus events). A workaround: to turn off separate layouts for each window: Settings => Keyboard => Layouts, uncheck "Separate layout for each window."</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload