java-gnome version 4.0.13

org.gnome.gdk
Class ModifierType

Object
  extended by org.freedesktop.bindings.Constant
      extended by org.freedesktop.bindings.Flag
          extended by org.gnome.gdk.ModifierType

public final class ModifierType
extends org.freedesktop.bindings.Flag

Constants representing what modifier keys are being held down on a keystroke, if any. You get an object containing flags that are set via the getState() method on the EventKey you receive when hooking up a Widget.KeyPressEvent or Widget.KeyReleaseEvent.

Try running this fragment if you're confused about the relationship between Keyvals, ModifierTypes, and the keyboard events:

 foo.connect(new Widget.KeyPressEvent() {
     public boolean onKeyPressEvent(Widget source, EventKey event) {
         final Keyval key;
         final ModifierType mod;
 
         key = event.getKeyval();
         mod = event.getState();
 
         System.out.print("Pressed: " + key.toString() + ", ");
         System.out.print("Modifier: " + mod.toString() + " ");
 
         if (mod == ModifierType.SHIFT_MASK) {
             System.out.print("That's Shifty!");
         }
         if (mod.contains(ModifierType.ALT_MASK)) {
             System.out.print("Hooray for Alt!");
         }
 
         System.out.println();
         return false;
     }
 });
 
For each of the following keystrokes, you'll get a sequence of output something like the following:
A
 Pressed: Keyval.a, Modifier: ModifierType.UNSET
 
Shift+A
 Pressed: Keyval.ShiftRight, Modifier: ModifierType.UNSET 
 Pressed: Keyval.A, Modifier: ModifierType.SHIFT_MASK That's Shifty!
 
Ctrl+A
 Pressed: Keyval.ControlRight, Modifier: ModifierType.UNSET 
 Pressed: Keyval.a, Modifier: ModifierType.CONTROL_MASK
 
Ctrl+Shift+A
 Pressed: Keyval.ControlRight, Modifier: ModifierType.UNSET  
 Pressed: Keyval.ShiftRight, Modifier: ModifierType.CONTROL_MASK 
 Pressed: Keyval.A, Modifier: ModifierType.SHIFT_MASK|CONTROL_MASK
 
Alt+A
 Pressed: Keyval.AltRight, Modifier: ModifierType.UNSET 
 Pressed: Keyval.a, Modifier: ModifierType.ALT_MASK Hooray for Alt!
 
Ctrl+Alt+A
 Pressed: Keyval.ControlLeft, Modifier: ModifierType.UNSET 
 Pressed: Keyval.AltLeft, Modifier: ModifierType.CONTROL_MASK 
 Pressed: Keyval.a, Modifier: ModifierType.CONTROL_MASK|ALT_MASK Hooray for Alt!
 

The sequence of keystrokes for the modifying keys will depend on the order the user strikes them, but you won't get them showing up as ModifierType constants until a "normal" key is hit. Incidentally, this is where the usefulness of Keyval's toUnicode() come in: you can filter key events until you get one with a non-0 translation.

As with Keyval there are many other modifier constants that we haven't bothered to expose. If you need one, feel free to subclass this and add it.

Since:
4.0.6
Author:
Andrew Cowie

Field Summary
static ModifierType ALT_MASK
          The Alt key modifier.
static ModifierType CONTROL_MASK
          The Control key modifier.
static ModifierType HYPER_MASK
           
static ModifierType LOCK_MASK
          The ModifierType associated with the CapsLock key.
static ModifierType NONE
          No modifiers were pressed.
static ModifierType SHIFT_MASK
          The Shift key modifier.
static ModifierType SUPER_MASK
           
static ModifierType WINDOW_MASK
          The Window modifier key.
 
Method Summary
 
Methods inherited from class org.freedesktop.bindings.Flag
contains
 
Methods inherited from class org.freedesktop.bindings.Constant
toString
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ALT_MASK

public static final ModifierType ALT_MASK
The Alt key modifier.

The legacy code in the X server as wrapped by GDK has this as MOD1_MASK; you should probably be aware that it is possible that Alt could be mapped to a different modifier, There are, however, a number of hard coded references tying Mod1 to the Alt key in various places, notably gnome-control-center's gnome-keybinding-properties, so calling this ALT_MASK seems safe enough.

Since:
4.0.6

CONTROL_MASK

public static final ModifierType CONTROL_MASK
The Control key modifier.

Since:
4.0.6

HYPER_MASK

public static final ModifierType HYPER_MASK

LOCK_MASK

public static final ModifierType LOCK_MASK
The ModifierType associated with the CapsLock key. A bit strange that this is also treated as a modifier.

Since:
4.0.13

NONE

public static final ModifierType NONE
No modifiers were pressed.

Since:
4.0.6

SHIFT_MASK

public static final ModifierType SHIFT_MASK
The Shift key modifier.

Since:
4.0.6

SUPER_MASK

public static final ModifierType SUPER_MASK

WINDOW_MASK

public static final ModifierType WINDOW_MASK
The Window modifier key. You will probably also get SUPER_MASK with this one.

Unless your user has changed things of their X server is doing something weird, it is likely that MOD4_MASK is mapped to the "key with the Microsoft Windows logo" that is present on modern PC104 keyboards. Damn monopolists. Anyway, that's what people call it, so that's that's what we've named our constant.

Since:
4.0.6


java-gnome