Skip to main content

Add API for changing the current Keyboard Layout (?) programmatically

7 replies [Last post]
behrangsa
Offline
Joined: 2003-09-14
Points: 0

Hi all

I've installed two languages in my Windows environment: Farsi and English; and by pressing Alt+Shift I can switch between them. Windows API also allows to switch between languages programmatically.

I've seen many people asking how this can be done in Java and it looks like not only there's not a %100 pure Java solution for this problem but also it's not easily accomplishable using JNI (maybe even it's not possible at all.)

This is a very important feature for Farsi/Hebrew/Arabic and possibly other RTL language users who both input English LTR text and also Farsi/Hebrew/Arabic RTL text.

Regards,
Behrang S.

Message was edited by: behrangsa (Typo error :-)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cowwoc
Offline
Joined: 2003-08-24
Points: 0

+1

One major problem we had with Netbeans "back in the day" is that when I was running under OS/2 and the team wasn't aware of the OS-specific shortcut keys and they mapped keys that were quasi-reserved by the OS to Netbeans. What ended up happening is that under OS/2 you could not use those shortcuts.

Having the ability to change the keyboard layout (whether for locale reasons or for the ability to change the default behavior of shortcut keys) it is important in order to deliver consist behavior across all platforms. This is comparable to the cross-platform L&F.

BTW: Here is the related bug ID: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4351840

Gili

kirillcool
Offline
Joined: 2004-11-17
Points: 0

Zander,

Changing the layout does [b]not[/b] affect all the applications, only the one in the foreground. I know this since i work in BIDI environment (Hebrew-English).
Each application that wishes to support Hebrew layout can do so automatically (when it is launched) or allow the user to store the layout as preference (so the next time it is launched, it restores the layout).

The same, by the way, goes for new Eclipse3.1: it takes the Locale and derives the direction of the GUI from it (not to mention the fact that RTL layout looks very ugly).

This proposal is very valid, especially given that Java has gone to such great lengths with i18n and l10n in the last two releases.

Kirill

podlesh
Offline
Joined: 2004-07-26
Points: 0

It depends on OS/desktop: some of them has global keyboard mapping (including some older versions of Windows), some of them maintains different state for each application (windows 2000, XP).

This feature is very platform-dependent and almost impossible to implement on some of them (X window). If you want just one platform (and obviously this is the case), you can use JNI.

-1

njs
Offline
Joined: 2004-03-11
Points: 0

I recently replied to a similar question at javadesktop.org. Please take a look at:

http://www.javadesktop.org/forums/thread.jspa?threadID=8104&tstart=0

Thanks,
Naoto

gurra
Offline
Joined: 2005-01-31
Points: 0

The reason why I am browsing this thread is that my keyboard locale in eclipse editor, somehow sometimes (misstyping), is changing to US layout.
I want to be able to restore the locale to swedish without having to restart eclipse.

Probably there already exist a key combination for changing keyboard locale but the question is which..
/GD

zander
Offline
Joined: 2003-06-13
Points: 0

Please explain to us why this needs to be done from java; there is a specific application to change keyboard layouts, and its part of the OS. Changing the layout will do that for all running applications, including Java.

Why would one of these applications want to call this part of the operating system at all? The OS does all this for you, including the changing via a keyboard shourtcut.

In other words; what you want is part of the operating system; what is the point of doing the same thing twice.

behrangsa
Offline
Joined: 2003-09-14
Points: 0

As you know people run different kinds of applications on their systems. And for each of these applications they may have a preferred language to use it with. This is specially true for people that their mother tongue is not English.

For example, although that my mother tongue is Persian I mostly use English when I use my Web browser so I like its keyboard layout to be in English mode when I start it. I don't want to press Alt+Shift every time I start it up.

However there are applications that I like Farsi to be set as their default language. Such as Farsi encyclopedias or dictionaries. I don't want to press Alt+Shift to change the keyboard layout to Farsi everytime I use them.

Also in some Swing applications there are text fields or other components that only accept Farsi text and components that only accept English text. If I could change the active keyboard layout using a Java API I could register a focus listener with them and change the active layout whenever one of these components gain focus.

We had written a data entry application for one of our customers and they asked us to do this (set the keyboard layout to Farsi on startup) and after extensive googling and posting messages to the Java forums we found out that many other people have also wanted to do this but they have not been successful and we told our customer that IT CANNOT BE DONE IN JAVA!

Believe me. Being able to change the current active layout is a most have in many RTL+LTR applications. Once I was browsing through the source code of Eclipse and SWT and (I guess) I found code snippets that added this functionality to it...

Best Regards,
Behrang S.