KeyCode abstract#
Defines the keycode values for keys that are returned by KeyboardEvent.keyCode.
Important note: There is substantial divergence in how different browsers handle keycodes and their variants in different locales/keyboard layouts. We provide these constants to help make code processing keys more readable.
Constructors#
KeyCode()#
Properties#
hashCode no setter inherited#
The hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from Object.
Implementation
external int get hashCode;
runtimeType no setter inherited#
A representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;
Methods#
noSuchMethod() inherited#
Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dynamic object = 1;
object.add(42); // Statically allowed, run-time error
This invalid code will invoke the noSuchMethod method
of the integer 1 with an Invocation
representing the
.add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}
This code has no compile-time warnings or errors even though
the MockList class has no concrete implementation of
any of the List interface methods.
Calls to List methods are forwarded to noSuchMethod,
so this code will log an invocation similar to
Invocation.method(#add, [42])
and then throw.
If a value is returned from noSuchMethod,
it becomes the result of the original invocation.
If the value is not of a type that can be returned by the original
invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);
toString() inherited#
A string representation of this object.
Some classes have a default textual representation,
often paired with a static parse function (like int.parse).
These classes will provide the textual representation as
their string representation.
Other classes have no meaningful textual representation
that a program will care about.
Such classes will typically override toString to provide
useful information when inspecting the object,
mainly for debugging or logging.
Inherited from Object.
Implementation
external String toString();
Operators#
operator ==() inherited#
The equality operator.
The default behavior for all Objects is to return true if and
only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.-
Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false. -
Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from Object.
Implementation
external bool operator ==(Object other);
Static Methods#
isCharacterKey()#
Returns true if the keyCode produces a (US keyboard) character. Note: This does not (yet) cover characters on non-US keyboards (Russian, Hebrew, etc.).
Implementation
static bool isCharacterKey(int keyCode) {
if ((keyCode >= ZERO && keyCode <= NINE) ||
(keyCode >= NUM_ZERO && keyCode <= NUM_MULTIPLY) ||
(keyCode >= A && keyCode <= Z)) {
return true;
}
// Safari sends zero key code for non-latin characters.
if (Device.isWebKit && keyCode == 0) {
return true;
}
return (keyCode == SPACE ||
keyCode == QUESTION_MARK ||
keyCode == NUM_PLUS ||
keyCode == NUM_MINUS ||
keyCode == NUM_PERIOD ||
keyCode == NUM_DIVISION ||
keyCode == SEMICOLON ||
keyCode == FF_SEMICOLON ||
keyCode == DASH ||
keyCode == EQUALS ||
keyCode == FF_EQUALS ||
keyCode == COMMA ||
keyCode == PERIOD ||
keyCode == SLASH ||
keyCode == APOSTROPHE ||
keyCode == SINGLE_QUOTE ||
keyCode == OPEN_SQUARE_BRACKET ||
keyCode == BACKSLASH ||
keyCode == CLOSE_SQUARE_BRACKET);
}
Constants#
A#
Implementation
static const int A = 65;
ALT#
Implementation
static const int ALT = 18;
APOSTROPHE#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int APOSTROPHE = 192;
B#
Implementation
static const int B = 66;
BACKSLASH#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int BACKSLASH = 220;
BACKSPACE#
Implementation
static const int BACKSPACE = 8;
C#
Implementation
static const int C = 67;
CAPS_LOCK#
Implementation
static const int CAPS_LOCK = 20;
CLOSE_SQUARE_BRACKET#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int CLOSE_SQUARE_BRACKET = 221;
COMMA#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int COMMA = 188;
CONTEXT_MENU#
Implementation
static const int CONTEXT_MENU = 93;
CTRL#
Implementation
static const int CTRL = 17;
D#
Implementation
static const int D = 68;
DASH#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int DASH = 189;
DELETE#
Implementation
static const int DELETE = 46;
DOWN#
Implementation
static const int DOWN = 40;
E#
Implementation
static const int E = 69;
EIGHT#
Implementation
static const int EIGHT = 56;
END#
Implementation
static const int END = 35;
ENTER#
Implementation
static const int ENTER = 13;
EQUALS#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int EQUALS = 187;
ESC#
Implementation
static const int ESC = 27;
F#
Implementation
static const int F = 70;
F1#
Implementation
static const int F1 = 112;
F2#
Implementation
static const int F2 = 113;
F3#
Implementation
static const int F3 = 114;
F4#
Implementation
static const int F4 = 115;
F5#
Implementation
static const int F5 = 116;
F6#
Implementation
static const int F6 = 117;
F7#
Implementation
static const int F7 = 118;
F8#
Implementation
static const int F8 = 119;
F9#
Implementation
static const int F9 = 120;
F10#
Implementation
static const int F10 = 121;
F11#
Implementation
static const int F11 = 122;
F12#
Implementation
static const int F12 = 123;
FF_EQUALS#
Implementation
static const int FF_EQUALS = 61;
FF_SEMICOLON#
Implementation
static const int FF_SEMICOLON = 59;
FIRST_MEDIA_KEY#
Implementation
static const int FIRST_MEDIA_KEY = 166;
FIVE#
Implementation
static const int FIVE = 53;
FOUR#
Implementation
static const int FOUR = 52;
G#
Implementation
static const int G = 71;
H#
Implementation
static const int H = 72;
HOME#
Implementation
static const int HOME = 36;
I#
Implementation
static const int I = 73;
INSERT#
Implementation
static const int INSERT = 45;
J#
Implementation
static const int J = 74;
K#
Implementation
static const int K = 75;
L#
Implementation
static const int L = 76;
LAST_MEDIA_KEY#
Implementation
static const int LAST_MEDIA_KEY = 183;
LEFT#
Implementation
static const int LEFT = 37;
M#
Implementation
static const int M = 77;
MAC_ENTER#
Implementation
static const int MAC_ENTER = 3;
MAC_FF_META#
Implementation
static const int MAC_FF_META = 224;
META#
Implementation
static const int META = 91;
N#
Implementation
static const int N = 78;
NINE#
Implementation
static const int NINE = 57;
NUM_CENTER#
NUM_CENTER is also NUMLOCK for FF and Safari on Mac.
Implementation
static const int NUM_CENTER = 12;
NUM_DELETE#
Implementation
static const int NUM_DELETE = 46;
NUM_DIVISION#
Implementation
static const int NUM_DIVISION = 111;
NUM_EAST#
Implementation
static const int NUM_EAST = 39;
NUM_EIGHT#
Implementation
static const int NUM_EIGHT = 104;
NUM_FIVE#
Implementation
static const int NUM_FIVE = 101;
NUM_FOUR#
Implementation
static const int NUM_FOUR = 100;
NUM_INSERT#
Implementation
static const int NUM_INSERT = 45;
NUM_MINUS#
Implementation
static const int NUM_MINUS = 109;
NUM_MULTIPLY#
Implementation
static const int NUM_MULTIPLY = 106;
NUM_NINE#
Implementation
static const int NUM_NINE = 105;
NUM_NORTH#
Implementation
static const int NUM_NORTH = 38;
NUM_NORTH_EAST#
Implementation
static const int NUM_NORTH_EAST = 33;
NUM_NORTH_WEST#
Implementation
static const int NUM_NORTH_WEST = 36;
NUM_ONE#
Implementation
static const int NUM_ONE = 97;
NUM_PERIOD#
Implementation
static const int NUM_PERIOD = 110;
NUM_PLUS#
Implementation
static const int NUM_PLUS = 107;
NUM_SEVEN#
Implementation
static const int NUM_SEVEN = 103;
NUM_SIX#
Implementation
static const int NUM_SIX = 102;
NUM_SOUTH#
Implementation
static const int NUM_SOUTH = 40;
NUM_SOUTH_EAST#
Implementation
static const int NUM_SOUTH_EAST = 34;
NUM_SOUTH_WEST#
Implementation
static const int NUM_SOUTH_WEST = 35;
NUM_THREE#
Implementation
static const int NUM_THREE = 99;
NUM_TWO#
Implementation
static const int NUM_TWO = 98;
NUM_WEST#
Implementation
static const int NUM_WEST = 37;
NUM_ZERO#
Implementation
static const int NUM_ZERO = 96;
NUMLOCK#
Implementation
static const int NUMLOCK = 144;
O#
Implementation
static const int O = 79;
ONE#
Implementation
static const int ONE = 49;
OPEN_SQUARE_BRACKET#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int OPEN_SQUARE_BRACKET = 219;
P#
Implementation
static const int P = 80;
PAGE_DOWN#
Implementation
static const int PAGE_DOWN = 34;
PAGE_UP#
Implementation
static const int PAGE_UP = 33;
PAUSE#
Implementation
static const int PAUSE = 19;
PERIOD#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int PERIOD = 190;
PRINT_SCREEN#
Implementation
static const int PRINT_SCREEN = 44;
Q#
Implementation
static const int Q = 81;
QUESTION_MARK#
CAUTION: The question mark is for US-keyboard layouts. It varies for other locales and keyboard layouts.
Implementation
static const int QUESTION_MARK = 63;
R#
Implementation
static const int R = 82;
RIGHT#
Implementation
static const int RIGHT = 39;
S#
Implementation
static const int S = 83;
SCROLL_LOCK#
Implementation
static const int SCROLL_LOCK = 145;
SEMICOLON#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int SEMICOLON = 186;
SEVEN#
Implementation
static const int SEVEN = 55;
SHIFT#
Implementation
static const int SHIFT = 16;
SINGLE_QUOTE#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int SINGLE_QUOTE = 222;
SIX#
Implementation
static const int SIX = 54;
SLASH#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int SLASH = 191;
SPACE#
Implementation
static const int SPACE = 32;
T#
Implementation
static const int T = 84;
TAB#
Implementation
static const int TAB = 9;
THREE#
Implementation
static const int THREE = 51;
TILDE#
CAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
static const int TILDE = 192;
TWO#
Implementation
static const int TWO = 50;
U#
Implementation
static const int U = 85;
UNKNOWN#
A sentinel value if the keycode could not be determined.
Implementation
static const int UNKNOWN = -1;
UP#
Implementation
static const int UP = 38;
V#
Implementation
static const int V = 86;
W#
Implementation
static const int W = 87;
WIN_IME#
Implementation
static const int WIN_IME = 229;
WIN_KEY#
Implementation
static const int WIN_KEY = 224;
WIN_KEY_FF_LINUX#
Implementation
static const int WIN_KEY_FF_LINUX = 0;
WIN_KEY_LEFT#
Implementation
static const int WIN_KEY_LEFT = 91;
WIN_KEY_RIGHT#
Implementation
static const int WIN_KEY_RIGHT = 92;
X#
Implementation
static const int X = 88;
Y#
Implementation
static const int Y = 89;
Z#
Implementation
static const int Z = 90;
ZERO#
Implementation
static const int ZERO = 48;