Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Setting keyboard layout different to the system's default
Setting keyboard layout different to the system's default [message #552973] Sun, 15 August 2010 12:50 Go to next message
Martin Fluegge is currently offline Martin Fluegge
Messages: 141
Registered: July 2009
Senior Member
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.

Cheers,

Martin
Re: Setting keyboard layout different to the system's default [message #553104 is a reply to message #552973] Mon, 16 August 2010 13:29 Go to previous messageGo to next message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
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.
>
> Cheers,
>
> Martin

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
and 280824.

--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Setting keyboard layout different to the system's default [message #553334 is a reply to message #553104] Tue, 17 August 2010 08:08 Go to previous messageGo to next message
Martin Fluegge is currently offline Martin Fluegge
Messages: 141
Registered: July 2009
Senior Member
Hi Pascal,

thanks for your reply. Smile

>This is kind of a recurring problem: people don't seem to grasp
>how this keyboard thingy works. Granted, it's a bit nebulous...

Well, I think I got the main part of it. Except my missunderstanding that SWTBot is changing the layout. Wink
Actually this based on my observation that when I changed my keyboard layout to EN_US using the short cut ALT+SHIFT it was resettet to the default when executing the test.
I thought that ALT + SHIFT changes the locale for the OS but in fact it only changes it for the current program. Silly me!

>1. Set your OS keyboard to EN_US
>2. Set SWTBotPreferences.KEYBOARD_LAYOUT to EN_US

I see. But for non-EN key developers this would mean to switch the keyboard every time they execute the test or to get used to an EN_US layout. I think both options are not a real good solution (Though I understand that there is currently no other way).

I know that AWT applications can change the keyboard layout (afair even at runtime). Probably there is some JNI involved there.

SWTBot could also gain access to the particular OS operation (using JNI) to set the keyboard layout of the OS when the test starts. This would make the whole keyboard story easy. Smile

What do you think?

Cheers,

Martin
Re: Setting keyboard layout different to the system's default [message #554382 is a reply to message #553334] Sun, 22 August 2010 18:08 Go to previous messageGo to next message
Marko Tomljenovic is currently offline Marko Tomljenovic
Messages: 62
Registered: July 2009
Member
I have created a DE_DE keyboard file here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=322186

It works for almost all keys (see issue for more info).

Hopefully Ketan will integrate it soon.
Re: Setting keyboard layout different to the system's default [message #554704 is a reply to message #554382] Tue, 24 August 2010 07:17 Go to previous messageGo to next message
Martin Fluegge is currently offline Martin Fluegge
Messages: 141
Registered: July 2009
Senior Member
Hi Marko,

thanks for your work. I'll try it as soon as possible. Smile

Btw. Does anyone know whether there is an overview over already integrated layouts?

I searched for it but only found the EN_US layout integrated in SWTBot. Maybe our team can contribute others.
Re: Setting keyboard layout different to the system's default [message #554859 is a reply to message #554704] Tue, 24 August 2010 14:46 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan Padegaonkar
Messages: 873
Registered: July 2009
Senior Member
On 8/24/10 12:17 AM, Martin Fluegge wrote:
> Hi Marko,
>
> thanks for your work. I'll try it as soon as possible. :)
>
> Btw. Does anyone know whether there is an overview over already
> integrated layouts?
>
> I searched for it but only found the EN_US layout integrated in SWTBot.
> Maybe our team can contribute others.

That helps a lot. I must admit that the existing keyboard stuff written
by me, is a complete disaster. I'm currently aware of a US and DE
layout. Designing the keyboard 'stuff' in SWTBot is a lot harder unless
I get to understand other keyboard layouts.

--
Ketan
http://ketan.padegaonkar.name | http://eclipse.org/swtbot
Re: Setting keyboard layout different to the system's default [message #555594 is a reply to message #554859] Fri, 27 August 2010 09:33 Go to previous message
Martin Fluegge is currently offline Martin Fluegge
Messages: 141
Registered: July 2009
Senior Member
> That helps a lot. I must admit that the existing keyboard stuff written
> by me, is a complete disaster.

I don't think that it's a complete disaster. It basically works. That's
what matters ;)

> I'm currently aware of a US and DE layout.

I started creating a wiki page which gives an overview about exiting (or
comming) layouts. You can drop it if you do not like it, but I think
this could encourage others to contribute their specific keyboard layouts.

http://wiki.eclipse.org/SWTBot/Existing_Keyboard_Layouts

Cheers,

Martin
Previous Topic:How to test defineLayout method from IPerspectiveFactory
Next Topic:Tests not executing in specified order
Goto Forum:
  


Current Time: Sat Oct 25 11:23:55 GMT 2014

Powered by FUDForum. Page generated in 0.01937 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software