Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SWTBot/Keyboard Layouts"

(added a page for keyboard layouts)
 
(No difference)

Revision as of 04:22, 20 May 2009

Keyboard Layouts in SWTBot

Introduction

Since the changes in bug 273624: Provide native keyboard support for use with Display.post it is now possible to send native keyboard events to widgets. SWTBot provides for pluggable strategies to be able to send events to your applications. Some strategies require that they understand different types of keyboard layouts.

Why keyboard layouts are important

Assuming that CAPS LOCK is turned off, if you need to type the string 'Hello'. You need to press the following key sequence: SHIFT+H, E, L, L, O. Similarly special characters like !, #, $, :, " etc need special treatment.

The keyboard layout determines how these characters are typed on the keyboard. A SHIFT+3 on a UK keyboard represents a '#' while on a UK keyboard it represents a '£'.

How do you define your own keyboard layout ?

To define your keyboard layout either:

  • set the system property "org.eclipse.swtbot.keyboard.layout" OR
  • set the variable SWTBotPreferences#KEYBOARD_LAYOUT

The value of this property should be of the form foo.bar.baz.[MAC.][upper-case-two-character-country-code]. For e.g. com.foo.bar.US or com.foo.bar.MAC.FR. The prefix ".MAC" is required for macosx keyboard.

Once you've defined the property, it is required to define the keyboard layout. For this purpose you need to create a config file called [MAC.][upper-case-two-character-country-code].keyboard in the package com.foo.bar.baz. For e.g. com/foo/bar/US.keyboard or com/foo/bar/MAC.FR.keyboard.

See KeyboardLayoutTest for how this is defined and the folder containing the layouts for an example.

Configuration file format

Next comes the configuration file format. The file is a simple text file with the following format:

<CHARACTER> <KEY_COMBINATION>

The <CHARACTER> is the complex character that needs to be typed, and the <KEY_COMBINATION> is the combination that types the <CHARACTER>. Valid <KEY_COMBINATION>s are:

  • CTRL
  • SHIFT
  • ALT
  • COMMAND
  • any other keys on the keyboard, capitalized. 'T' is valid, 't' is not. Similarly '3' on a US keyboard is valid '#' is not.

An example is:

! shift + 1
@ shift + 2
# shift + 3
$ shift + 4

Copyright © Eclipse Foundation, Inc. All Rights Reserved.