java-gnome version 4.0.19

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 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.NONE
 
Shift+A
 Pressed: Keyval.ShiftRight, Modifier: ModifierType.NONE 
 Pressed: Keyval.A, Modifier: ModifierType.SHIFT_MASK That's Shifty!
 
Ctrl+A
 Pressed: Keyval.ControlRight, Modifier: ModifierType.NONE 
 Pressed: Keyval.a, Modifier: ModifierType.CONTROL_MASK
 
Ctrl+Shift+A
 Pressed: Keyval.ControlRight, Modifier: ModifierType.NONE  
 Pressed: Keyval.ShiftRight, Modifier: ModifierType.CONTROL_MASK 
 Pressed: Keyval.A, Modifier: ModifierType.SHIFT_MASK|CONTROL_MASK
 
Alt+A
 Pressed: Keyval.AltRight, Modifier: ModifierType.NONE 
 Pressed: Keyval.a, Modifier: ModifierType.ALT_MASK Hooray for Alt!
 
Ctrl+Alt+A
 Pressed: Keyval.ControlLeft, Modifier: ModifierType.NONE 
 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 BUTTON_LEFT_MASK
          The left mouse button was held while the key was pressed.
static ModifierType BUTTON_MIDDLE_MASK
          The middle mouse button was held while the key was pressed.
static ModifierType BUTTON_RIGHT_MASK
          The right mouse button was held while the key was pressed.
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 NUM_MASK
          The ModifierType associated with the NumLock key.
static ModifierType SHIFT_MASK
          The Shift key modifier.
static ModifierType SUPER_MASK
           
static ModifierType WINDOW_MASK
          The Window modifier key.
 
Method Summary
static ModifierType and(ModifierType one, ModifierType two)
          Find the union of two ModifierType instances.
static ModifierType mask(ModifierType one, ModifierType two)
          Remove the second Flag's fields from the first.
static ModifierType or(ModifierType one, ModifierType two)
          Combine two ModifierType instances.
 
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

BUTTON_LEFT_MASK

public static final ModifierType BUTTON_LEFT_MASK
The left mouse button was held while the key was pressed. GNOME user interface conventions don't have us using mouse buttons as modifiers, so you won't need this in normal usage.

If hooking up a handler for Widget.ButtonPressEvent you will instead be using the LEFT MouseButton constant.

Since:
4.0.14

BUTTON_MIDDLE_MASK

public static final ModifierType BUTTON_MIDDLE_MASK
The middle mouse button was held while the key was pressed.

Since:
4.0.14

BUTTON_RIGHT_MASK

public static final ModifierType BUTTON_RIGHT_MASK
The right mouse button was held while the key was pressed.

Since:
4.0.14

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

NUM_MASK

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

Even worse is that this appears to actually be state 0x10, which is GDK_MOD2_MASK!

Since:
4.0.18

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
Method Detail

and

public static ModifierType and(ModifierType one,
                               ModifierType two)
Find the union of two ModifierType instances.

Since:
4.0.18

mask

public static ModifierType mask(ModifierType one,
                                ModifierType two)
Remove the second Flag's fields from the first. This is especially useful for screening out NumLock

Since:
4.0.18

or

public static ModifierType or(ModifierType one,
                              ModifierType two)
Combine two ModifierType instances.



java-gnome