public class ModifierType
extends org.freedesktop.bindings.Flag
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.
Modifier and Type | Field and Description |
---|---|
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. |
Modifier and Type | Method and Description |
---|---|
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.
|
public static final ModifierType ALT_MASK
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.
public static final ModifierType BUTTON_LEFT_MASK
If hooking up a handler for Widget.ButtonPressEvent
you
will instead be using the LEFT
MouseButton
constant.
public static final ModifierType BUTTON_MIDDLE_MASK
public static final ModifierType BUTTON_RIGHT_MASK
public static final ModifierType CONTROL_MASK
Control
key modifier.public static final ModifierType HYPER_MASK
public static final ModifierType LOCK_MASK
CapsLock
key.
A bit strange that this is also treated as a modifier.public static final ModifierType NONE
public static final ModifierType NUM_MASK
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
!
public static final ModifierType SHIFT_MASK
Shift
key modifier.public static final ModifierType SUPER_MASK
public static final ModifierType WINDOW_MASK
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.
public static ModifierType and(ModifierType one, ModifierType two)
public static ModifierType mask(ModifierType one, ModifierType two)
NumLock
public static ModifierType or(ModifierType one, ModifierType two)