gtk-0.12.2: Binding to the Gtk+ graphical user interface library.

Portabilityportable (depends on GHC)
Stabilityprovisional
Maintainergtk2hs-users@lists.sourceforge.net

Graphics.UI.Gtk.Gdk.Keymap

Contents

Description

Functions for manipulating keyboard codes

Synopsis

Details

Key values are the codes which are sent whenever a key is pressed or released. They appear in the keyval field of the EventKey structure, which is passed to signal handlers for the keyPressEvent and keyReleaseEvent signals.

Key values are regularly updated from the upstream X.org X11 implementation, so new values are added regularly. They will be prefixed with GDK_ rather than XF86XK_ or ' (for older symbols)'.

Key values can be converted into a string representation using keyvalName. The reverse function, converting a string to a key value, is provided by keyvalFromName.

The case of key values can be determined using keyvalIsUpper. Key values can be converted to upper or lower case using keyvalToUpper and keyvalToLower.

When it makes sense, key values can be converted to and from Unicode characters with keyvalToUnicode.

One Keymap object exists for each user display. keymapGetDefault returns the Keymap for the default display; to obtain keymaps for other displays, use keymapGetForDisplay. A keymap is a mapping from KeymapKey to key values. You can think of a KeymapKey as a representation of a symbol printed on a physical keyboard key. That is, it contains three pieces of information. First, it contains the hardware keycode; this is an identifying number for a physical key. Second, it contains the level of the key. The level indicates which symbol on the key will be used, in a vertical direction. So on a standard US keyboard, the key with the number "1" on it also has the exclamation point "!" character on it. The level indicates whether to use the "1" or the "!" symbol. The letter keys are considered to have a lowercase letter at level 0, and an uppercase letter at level 1, though only the uppercase letter is printed. Third, the KeymapKey contains a group; groups are not used on standard US keyboards, but are used in many other countries. On a keyboard with groups, there can be 3 or 4 symbols printed on a single key. The group indicates movement in a horizontal direction. Usually groups are used for two different languages. In group 0, a key might have two English characters, and in group 1 it might have two Hebrew characters. The Hebrew characters will be printed on the key next to the English characters.

In order to use a keymap to interpret a key event, it's necessary to first convert the keyboard state into an effective group and level. This is done via a set of rules that varies widely according to type of keyboard and user configuration. The function keymapTranslateKeyboardState accepts a keyboard state -- consisting of hardware keycode pressed, active modifiers, and active group -- applies the appropriate rules, and returns the group/level to be used to index the keymap, along with the modifiers which did not affect the group and level. i.e. it returns unconsumed modifiers. The keyboard group may differ from the effective group used for keymap lookups because some keys don't have multiple groups - e.g. the Enter key is always in group 0 regardless of keyboard state.

Note that keymapTranslateKeyboardState also returns the keyval, i.e. it goes ahead and performs the keymap lookup in addition to telling you which effective group/level values were used for the lookup. EventKey already contains this keyval, however, so you don't normally need to call keymapTranslateKeyboardState just to get the keyval.

Class Hierarchy

 | GObject
 | +----Keymap

Types

data KeymapKey Source

A KeymapKey is a hardware key that can be mapped to a keyval.

Methods

keymapGetDefaultSource

Arguments

:: IO Keymap

returns the Keymap attached to the default display.

Returns the Keymap attached to the default display.

keymapGetForDisplaySource

Arguments

:: Display

display - the Display.

-> IO Keymap

returns the Keymap attached to display.

Returns the Keymap attached to display.

  • Available since Gdk version 2.2

keymapLookupKeySource

Arguments

:: KeymapClass self 
=> Maybe self

keymap a Keymap or Nothing to use the default keymap

-> KeymapKey

key - a KeymapKey with keycode, group, and level initialized

-> IO Int

returns a keyval, or 0 if none was mapped to the given key

Looks up the keyval mapped to a keycode/group/level triplet. If no keyval is bound to key, returns 0. For normal user input, you want to use keymapTranslateKeyboardState instead of this function, since the effective group/level may not be the same as the current keyboard state.

keymapTranslateKeyboardStateSource

Arguments

:: KeymapClass self 
=> self 
-> Int

hardwareKeycode - a keycode

-> Modifier

state - a modifier state

-> Int

group - active keyboard group

-> IO (Maybe (Int, Int, Int, Modifier)) 

Translates the contents of a EventKey into a keyval, effective group, and level. Modifiers that affected the translation and are thus unavailable for application use are returned in consumedModifiers. See keyvalGetKeys for an explanation of groups and levels. The effectiveGroup is the group that was actually used for the translation; some keys such as Enter are not affected by the active keyboard group. The level is derived from state. For convenience, EventKey already contains the translated keyval, so this function isn't as useful as you might think.

keymapGetEntriesForKeyvalSource

Arguments

:: KeymapClass self 
=> self 
-> KeyVal

keyval - a keyval, such as GDK_a, GDK_Up, GDK_Return, etc.

-> IO (Maybe [KeymapKey]) 

Obtains a list of keycode/group/level combinations that will generate keyval. Groups and levels are two kinds of keyboard mode; in general, the level determines whether the top or bottom symbol on a key is used, and the group determines whether the left or right symbol is used. On US keyboards, the shift key changes the keyboard level, and there are no groups. A group switch key might convert a keyboard between Hebrew to English modes, for example. EventKey contains a group field that indicates the active keyboard group. The level is computed from the modifier mask.

keymapGetEntriesForKeycodeSource

Arguments

:: KeymapClass self 
=> self 
-> Int

hardwareKeycode - a keycode

-> IO (Maybe ([KeymapKey], [KeyVal])) 

Returns the keyvals bound to hardwareKeycode. The Nth KeymapKey in keys is bound to the Nth keyval in keyvals. When a keycode is pressed by the user, the keyval from this list of entries is selected by considering the effective keyboard group and level. See keymapTranslateKeyboardState.

keymapGetDirectionSource

Arguments

:: KeymapClass self 
=> self 
-> IO PangoDirection

returns DirectionLtr or DirectionRtl if it can determine the direction. DirectionNeutral otherwise.

Returns the direction of effective layout of the keymap.

Returns the direction of the keymap.

keymapHaveBidiLayoutsSource

Arguments

:: KeymapClass self 
=> self 
-> IO Bool

returns True if there are layouts in both directions, False otherwise

Determines if keyboard layouts for both right-to-left and left-to-right languages are in use.

  • Available since Gdk version 2.12

keymapGetCapsLockStateSource

Arguments

:: KeymapClass self 
=> self 
-> IO Bool

returns True if Caps Lock is on

Returns whether the Caps Lock modifer is locked.

  • Available since Gdk version 2.16

Signals

keymapDirectionChanged :: KeymapClass self => Signal self (IO ())Source

The keymapDirectionChanged signal gets emitted when the direction of the keymap changes.

  • Available since Gdk version 2.0

keymapKeysChanged :: KeymapClass self => Signal self (IO ())Source

The keymapKeysChanged signal is emitted when the mapping represented by keymap changes.

  • Available since Gdk version 2.2

keymapStateChanged :: KeymapClass self => Signal self (IO ())Source

The keymapStateChanged signal is emitted when the state of the keyboard changes, e.g when Caps Lock is turned on or off. See keymapGetCapsLockState.

  • Available since Gdk version 2.16