public class Keyval
extends org.freedesktop.bindings.Constant
It is important to note that lower case and upper case letters are
considered different keys even though most keyboards present but a single
physical button with an A
showing. Think of that
physical key as having both an a
and an
A
printed on it, with the second being the key reached if
the Shift
modifier is held down. Have a look at the
ModifierType
class for a discussion of how to deal with the
modifying keys and for a better understanding of the sequence in which key
events occur.
Looking for 1
through 9
? See
Num0
to Num9
.
The correlation between keys and Unicode characters is a complex one. For
basic western ISO Latin letters the keys we press and the characters we get
are, to all intents and purposes, one and the same. But there are many
thousands of additional characters for which you probably don't have keys
for, even if you have (or have mapped something to be) the
Compose
key for taking the composite of several keystrokes
to generate special characters. Just remember that Keyvals are key
constants, not constants for every unicode character and you'll keep
things straight.
GDK deals with keyvals exclusively as int
s, and there are
over 1700 of them. Most of these "keys" are ridiculous or apply to hardware
that has long since ceased to exist. We've deliberately constrained this
class to a narrow range; experience in 2.x showed that even mighty Eclipse
chokes when asked to complete from a list that big. This leads us to two
consequences. 1) Constants will be registered for keyvals encountered that
haven't been explicitly created here, so you don't have to worry about some
nasty RuntimeException kicking your ass. 2) You can extend this Keyval
class as necessary to create your own constants if you need to. See
KeypadKeyval
for an example.
Modifier and Type | Field and Description |
---|---|
static Keyval |
a |
static Keyval |
A |
static Keyval |
AltLeft |
static Keyval |
AltRight |
static Keyval |
Ampersand |
static Keyval |
Apostrophe |
static Keyval |
Asterisk |
static Keyval |
AtSign |
static Keyval |
b |
static Keyval |
B |
static Keyval |
Backslash |
static Keyval |
BackSpace |
static Keyval |
BackTab
Reverse indentation key.
|
static Keyval |
Bar
Also known as Pipe (from the fact that this is used in a Unix shell to
"pipe" output from one command to another).
|
static Keyval |
BraceLeft |
static Keyval |
BraceRight |
static Keyval |
BracketLeft |
static Keyval |
BracketRight |
static Keyval |
Break |
static Keyval |
c |
static Keyval |
C |
static Keyval |
CapsLock |
static Keyval |
Circumflex
Also known as Carrot or Hat.
|
static Keyval |
Colon |
static Keyval |
Comma |
static Keyval |
Compose
The
Compose used to create high order characters
from pressing tis plus certain following key sequences. |
static Keyval |
ControlLeft |
static Keyval |
ControlRight |
static Keyval |
d |
static Keyval |
D |
static Keyval |
Delete |
static Keyval |
Dollar |
static Keyval |
Down |
static Keyval |
e |
static Keyval |
E |
static Keyval |
End |
static Keyval |
Equal |
static Keyval |
Escape |
static Keyval |
Exclaim |
static Keyval |
f |
static Keyval |
F |
static Keyval |
F1 |
static Keyval |
F10 |
static Keyval |
F11 |
static Keyval |
F12 |
static Keyval |
F2 |
static Keyval |
F3 |
static Keyval |
F4 |
static Keyval |
F5 |
static Keyval |
F6 |
static Keyval |
F7 |
static Keyval |
F8 |
static Keyval |
F9 |
static Keyval |
g |
static Keyval |
G |
static Keyval |
Grave |
static Keyval |
Greater |
static Keyval |
h |
static Keyval |
H |
static Keyval |
Home |
static Keyval |
i |
static Keyval |
I |
static Keyval |
Insert |
static Keyval |
j |
static Keyval |
J |
static Keyval |
k |
static Keyval |
K |
static Keyval |
l |
static Keyval |
L |
static Keyval |
Left |
static Keyval |
Less |
static Keyval |
m |
static Keyval |
M |
static Keyval |
Menu |
static Keyval |
Minus |
static Keyval |
n |
static Keyval |
N |
static Keyval |
Num0 |
static Keyval |
Num1 |
static Keyval |
Num2 |
static Keyval |
Num3 |
static Keyval |
Num4 |
static Keyval |
Num5 |
static Keyval |
Num6 |
static Keyval |
Num7 |
static Keyval |
Num8 |
static Keyval |
Num9 |
static Keyval |
NumberSign |
static Keyval |
NumLock |
static Keyval |
o |
static Keyval |
O |
static Keyval |
p |
static Keyval |
P |
static Keyval |
PageDown |
static Keyval |
PageUp |
static Keyval |
ParenLeft |
static Keyval |
ParenRight |
static Keyval |
Pause |
static Keyval |
Percent |
static Keyval |
Period |
static Keyval |
Plus |
static Keyval |
Print |
static Keyval |
q |
static Keyval |
Q |
static Keyval |
Question |
static Keyval |
QuoteDouble |
static Keyval |
QuoteSingle |
static Keyval |
r |
static Keyval |
R |
static Keyval |
Return |
static Keyval |
Right |
static Keyval |
s |
static Keyval |
S |
static Keyval |
ScrollLock |
static Keyval |
Semicolon |
static Keyval |
ShiftLeft |
static Keyval |
ShiftRight |
static Keyval |
Slash |
static Keyval |
Space |
static Keyval |
SuperLeft |
static Keyval |
SuperRight |
static Keyval |
SysReq |
static Keyval |
t |
static Keyval |
T |
static Keyval |
Tab
Normal indentation key.
|
static Keyval |
Tilde |
static Keyval |
u |
static Keyval |
U |
static Keyval |
Underscore |
static Keyval |
Up |
static Keyval |
v |
static Keyval |
V |
static Keyval |
w |
static Keyval |
W |
static Keyval |
x |
static Keyval |
X |
static Keyval |
y |
static Keyval |
Y |
static Keyval |
z |
static Keyval |
Z |
Modifier and Type | Method and Description |
---|---|
char |
toUnicode()
Translate this Keyval to a unicode representation.
|
public static final Keyval a
public static final Keyval A
public static final Keyval AltLeft
public static final Keyval AltRight
public static final Keyval Ampersand
public static final Keyval Apostrophe
public static final Keyval Asterisk
public static final Keyval AtSign
public static final Keyval b
public static final Keyval B
public static final Keyval Backslash
public static final Keyval BackSpace
public static final Keyval BackTab
This occurs on when you type Shift+Tab
. Normal
(forward) indentation keystrokes are the Tab
Keyval.
Backwards movement by an indent is a legacy from the age of
typewriters, and not used in text entry today. The
Shift+Tab
sequence is, however, used in GNOME to move
the keyboard focus one Widget back.
public static final Keyval Bar
public static final Keyval BraceLeft
public static final Keyval BraceRight
public static final Keyval BracketLeft
public static final Keyval BracketRight
public static final Keyval Break
public static final Keyval c
public static final Keyval C
public static final Keyval CapsLock
public static final Keyval Circumflex
public static final Keyval Colon
public static final Keyval Comma
public static final Keyval Compose
Compose
used to create high order characters
from pressing tis plus certain following key sequences.public static final Keyval ControlLeft
public static final Keyval ControlRight
public static final Keyval d
public static final Keyval D
public static final Keyval Delete
public static final Keyval Dollar
public static final Keyval Down
public static final Keyval e
public static final Keyval E
public static final Keyval End
public static final Keyval Equal
public static final Keyval Escape
public static final Keyval Exclaim
public static final Keyval f
public static final Keyval F
public static final Keyval F1
public static final Keyval F10
public static final Keyval F11
public static final Keyval F12
public static final Keyval F2
public static final Keyval F3
public static final Keyval F4
public static final Keyval F5
public static final Keyval F6
public static final Keyval F7
public static final Keyval F8
public static final Keyval F9
public static final Keyval g
public static final Keyval G
public static final Keyval Grave
public static final Keyval Greater
public static final Keyval h
public static final Keyval H
public static final Keyval Home
public static final Keyval i
public static final Keyval I
public static final Keyval Insert
public static final Keyval j
public static final Keyval J
public static final Keyval k
public static final Keyval K
public static final Keyval l
public static final Keyval L
public static final Keyval Left
public static final Keyval Less
public static final Keyval m
public static final Keyval M
public static final Keyval Menu
public static final Keyval Minus
public static final Keyval n
public static final Keyval N
public static final Keyval Num0
public static final Keyval Num1
public static final Keyval Num2
public static final Keyval Num3
public static final Keyval Num4
public static final Keyval Num5
public static final Keyval Num6
public static final Keyval Num7
public static final Keyval Num8
public static final Keyval Num9
public static final Keyval NumberSign
public static final Keyval NumLock
public static final Keyval o
public static final Keyval O
public static final Keyval p
public static final Keyval P
public static final Keyval PageDown
public static final Keyval PageUp
public static final Keyval ParenLeft
public static final Keyval ParenRight
public static final Keyval Pause
public static final Keyval Percent
public static final Keyval Period
public static final Keyval Plus
public static final Keyval Print
public static final Keyval q
public static final Keyval Q
public static final Keyval Question
public static final Keyval QuoteDouble
public static final Keyval QuoteSingle
public static final Keyval r
public static final Keyval R
public static final Keyval Return
public static final Keyval Right
public static final Keyval s
public static final Keyval S
public static final Keyval ScrollLock
public static final Keyval Semicolon
public static final Keyval ShiftLeft
public static final Keyval ShiftRight
public static final Keyval Slash
public static final Keyval Space
public static final Keyval SuperLeft
public static final Keyval SuperRight
public static final Keyval SysReq
public static final Keyval t
public static final Keyval T
public static final Keyval Tab
In normal GNOME user interface usage, this is used to move the keyboard
focus forwards from one Widget to the next. In text documents, however,
Tab
is typically used to insert a '\t'
character.
Be aware that on a standard GNOME desktop, Alt+Tab
is captured by the window manager used to change between applications,
so you likely won't receive it.
public static final Keyval Tilde
public static final Keyval u
public static final Keyval U
public static final Keyval Underscore
public static final Keyval Up
public static final Keyval v
public static final Keyval V
public static final Keyval w
public static final Keyval W
public static final Keyval x
public static final Keyval X
public static final Keyval y
public static final Keyval Y
public static final Keyval z
public static final Keyval Z
public char toUnicode()
One way this might be used is:
final Pattern regexAtoZ = Pattern.compile("[a-z]"); final Keyval key; final String str, result; str = "" + key.toUnicode(); if (key == Keyval.Return) { // execute } else if (key == Keyval.Escape) { // abort } else if (regexAtoZ.matcher(str).matches()) { entry.setText(str); } else { ... }which is a bit cumbersome, but illustrates one way of identifying "normal" letters being typed.
Not all keys have translations; in such cases 0
will be
returned. Testing for this can sometimes be an easier approach to
figuring out if a "normal" key was hit, but your mileage will vary
depending on the user's actual configuration. Note that that's
(char) 0
, not '0'
!
Be wary of appending this return value to a String!
Although Java won't lose the character or subsequent ones,
\0
is the "NULL
terminator" for
char*
strings in C and will prematurely terminate the
printed output if you try to print the String (as, after all, in the
final analysis the Java VM is nothing more than a C program and
eventually a C library routine will be called to output the text)!