|Re: Setting keyboard layout different to the system's default [message #553104 is a reply to message #552973]
||Mon, 16 August 2010 13:29
| Pascal G
Registered: July 2009
On 10-08-15 08:50 AM, Martin Flügge wrote:|
> Hi @all,
> I discovered a problem concerning the keyboard layouts. I am quite new
> the SWTBot, so please apologize if this question is a stupid one.
> I am going to write a test case which uses SWTBots's default
> KeyboardLayout, so I set the related property to "EN_US" (by default it
> is "DE_DE" on my system; Windows XP) like this:
> SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"
> But when executing something like this...
> Keyboard keyboard = KeyboardFactory.getSWTKeyboard();
> keyboard.typeText(":", 100);
> ...the test failes. To be exact, it types ";". When using an AWTKeyboard
> the test fails with "Invalid key code".
> I debugged through it and the key combination (SHIFT+;) is correctly
> identified, which means that SWTBot uses the EN_US layout.
> Then I found out that while the test is running the keyboard layout is
> set to the systems default (DE in my case). After the test finished the
> layout is set to what is was before. This seems to be the reason why the
> keyboard could not type the correct characters.
> I expected that setting SWTBotPreferences.KEYBOARD_LAYOUT to "EN_US"
> would be enough to configure that the test should run with this layout.
> Why is SWTBot switching to the system's default layout?
> Am I missing something obvious? Maybe another property which must be
> set? Or is this a bug?
> Thanks in advance.
This is kind of a recurring problem: people don't seem to grasp how this
keyboard thingy works. Granted, it's a bit nebulous...
The property SWTBotPreferences.KEYBOARD_LAYOUT only tells SWTBot what
keyboard mapping file to use, so that it can type special characters
properly. But setting this property doesn't change your OS Keyboard
mapping, Java can't do that. You'll need to do that yourself. So, for
this thing to work properly, you need to:
1. Set your OS keyboard to EN_US
2. Set SWTBotPreferences.KEYBOARD_LAYOUT to EN_US
You see, the property SWTBotPreferences.KEYBOARD_LAYOUT (and associated
mapping files) acts a bit like your physical keyboard: it tells you, the
user, that to type a ":" you need to press SHIFT+; because that's what
you see on your keyboard. But if your OS is using DE_DE, it won't work
because that is not how the OS translate the keycodes sent by the
keyboard. Changing the keyboard does not change the OS mappings...
I hope I helped clarified this feature a bit. For more information on
why you need to use EN_US only, see the associated bug reports 280562
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/
*Because performance matters.*
Powered by FUDForum
. Page generated in 0.02474 seconds