Appearance
KeyCode abstract ​
abstract class KeyCodeDefines 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() ​
KeyCode()Properties ​
hashCode no setter inherited ​
int get hashCodeThe 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
dart
external int get hashCode;runtimeType no setter inherited ​
Type get runtimeTypeA representation of the runtime type of the object.
Inherited from Object.
Implementation
dart
external Type get runtimeType;Methods ​
noSuchMethod() inherited ​
dynamic noSuchMethod(Invocation invocation)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:
dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time errorThis 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:
dart
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
dart
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);toString() inherited ​
String toString()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
dart
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
dart
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
dart
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 ​
const int AImplementation
dart
static const int A = 65;ALT ​
const int ALTImplementation
dart
static const int ALT = 18;APOSTROPHE ​
const int APOSTROPHECAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int APOSTROPHE = 192;B ​
const int BImplementation
dart
static const int B = 66;BACKSLASH ​
const int BACKSLASHCAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int BACKSLASH = 220;BACKSPACE ​
const int BACKSPACEImplementation
dart
static const int BACKSPACE = 8;C ​
const int CImplementation
dart
static const int C = 67;CAPS_LOCK ​
const int CAPS_LOCKImplementation
dart
static const int CAPS_LOCK = 20;CLOSE_SQUARE_BRACKET ​
const int CLOSE_SQUARE_BRACKETCAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int CLOSE_SQUARE_BRACKET = 221;COMMA ​
const int COMMACAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int COMMA = 188;CONTEXT_MENU ​
const int CONTEXT_MENUImplementation
dart
static const int CONTEXT_MENU = 93;CTRL ​
const int CTRLImplementation
dart
static const int CTRL = 17;D ​
const int DImplementation
dart
static const int D = 68;DASH ​
const int DASHCAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int DASH = 189;DELETE ​
const int DELETEImplementation
dart
static const int DELETE = 46;DOWN ​
const int DOWNImplementation
dart
static const int DOWN = 40;E ​
const int EImplementation
dart
static const int E = 69;EIGHT ​
const int EIGHTImplementation
dart
static const int EIGHT = 56;END ​
const int ENDImplementation
dart
static const int END = 35;ENTER ​
const int ENTERImplementation
dart
static const int ENTER = 13;EQUALS ​
const int EQUALSCAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int EQUALS = 187;ESC ​
const int ESCImplementation
dart
static const int ESC = 27;F ​
const int FImplementation
dart
static const int F = 70;F1 ​
const int F1Implementation
dart
static const int F1 = 112;F2 ​
const int F2Implementation
dart
static const int F2 = 113;F3 ​
const int F3Implementation
dart
static const int F3 = 114;F4 ​
const int F4Implementation
dart
static const int F4 = 115;F5 ​
const int F5Implementation
dart
static const int F5 = 116;F6 ​
const int F6Implementation
dart
static const int F6 = 117;F7 ​
const int F7Implementation
dart
static const int F7 = 118;F8 ​
const int F8Implementation
dart
static const int F8 = 119;F9 ​
const int F9Implementation
dart
static const int F9 = 120;F10 ​
const int F10Implementation
dart
static const int F10 = 121;F11 ​
const int F11Implementation
dart
static const int F11 = 122;F12 ​
const int F12Implementation
dart
static const int F12 = 123;FF_EQUALS ​
const int FF_EQUALSImplementation
dart
static const int FF_EQUALS = 61;FF_SEMICOLON ​
const int FF_SEMICOLONImplementation
dart
static const int FF_SEMICOLON = 59;FIRST_MEDIA_KEY ​
const int FIRST_MEDIA_KEYImplementation
dart
static const int FIRST_MEDIA_KEY = 166;FIVE ​
const int FIVEImplementation
dart
static const int FIVE = 53;FOUR ​
const int FOURImplementation
dart
static const int FOUR = 52;G ​
const int GImplementation
dart
static const int G = 71;H ​
const int HImplementation
dart
static const int H = 72;HOME ​
const int HOMEImplementation
dart
static const int HOME = 36;I ​
const int IImplementation
dart
static const int I = 73;INSERT ​
const int INSERTImplementation
dart
static const int INSERT = 45;J ​
const int JImplementation
dart
static const int J = 74;K ​
const int KImplementation
dart
static const int K = 75;L ​
const int LImplementation
dart
static const int L = 76;LAST_MEDIA_KEY ​
const int LAST_MEDIA_KEYImplementation
dart
static const int LAST_MEDIA_KEY = 183;LEFT ​
const int LEFTImplementation
dart
static const int LEFT = 37;M ​
const int MImplementation
dart
static const int M = 77;MAC_ENTER ​
const int MAC_ENTERImplementation
dart
static const int MAC_ENTER = 3;MAC_FF_META ​
const int MAC_FF_METAImplementation
dart
static const int MAC_FF_META = 224;META ​
const int METAImplementation
dart
static const int META = 91;N ​
const int NImplementation
dart
static const int N = 78;NINE ​
const int NINEImplementation
dart
static const int NINE = 57;NUM_CENTER ​
const int NUM_CENTERNUM_CENTER is also NUMLOCK for FF and Safari on Mac.
Implementation
dart
static const int NUM_CENTER = 12;NUM_DELETE ​
const int NUM_DELETEImplementation
dart
static const int NUM_DELETE = 46;NUM_DIVISION ​
const int NUM_DIVISIONImplementation
dart
static const int NUM_DIVISION = 111;NUM_EAST ​
const int NUM_EASTImplementation
dart
static const int NUM_EAST = 39;NUM_EIGHT ​
const int NUM_EIGHTImplementation
dart
static const int NUM_EIGHT = 104;NUM_FIVE ​
const int NUM_FIVEImplementation
dart
static const int NUM_FIVE = 101;NUM_FOUR ​
const int NUM_FOURImplementation
dart
static const int NUM_FOUR = 100;NUM_INSERT ​
const int NUM_INSERTImplementation
dart
static const int NUM_INSERT = 45;NUM_MINUS ​
const int NUM_MINUSImplementation
dart
static const int NUM_MINUS = 109;NUM_MULTIPLY ​
const int NUM_MULTIPLYImplementation
dart
static const int NUM_MULTIPLY = 106;NUM_NINE ​
const int NUM_NINEImplementation
dart
static const int NUM_NINE = 105;NUM_NORTH ​
const int NUM_NORTHImplementation
dart
static const int NUM_NORTH = 38;NUM_NORTH_EAST ​
const int NUM_NORTH_EASTImplementation
dart
static const int NUM_NORTH_EAST = 33;NUM_NORTH_WEST ​
const int NUM_NORTH_WESTImplementation
dart
static const int NUM_NORTH_WEST = 36;NUM_ONE ​
const int NUM_ONEImplementation
dart
static const int NUM_ONE = 97;NUM_PERIOD ​
const int NUM_PERIODImplementation
dart
static const int NUM_PERIOD = 110;NUM_PLUS ​
const int NUM_PLUSImplementation
dart
static const int NUM_PLUS = 107;NUM_SEVEN ​
const int NUM_SEVENImplementation
dart
static const int NUM_SEVEN = 103;NUM_SIX ​
const int NUM_SIXImplementation
dart
static const int NUM_SIX = 102;NUM_SOUTH ​
const int NUM_SOUTHImplementation
dart
static const int NUM_SOUTH = 40;NUM_SOUTH_EAST ​
const int NUM_SOUTH_EASTImplementation
dart
static const int NUM_SOUTH_EAST = 34;NUM_SOUTH_WEST ​
const int NUM_SOUTH_WESTImplementation
dart
static const int NUM_SOUTH_WEST = 35;NUM_THREE ​
const int NUM_THREEImplementation
dart
static const int NUM_THREE = 99;NUM_TWO ​
const int NUM_TWOImplementation
dart
static const int NUM_TWO = 98;NUM_WEST ​
const int NUM_WESTImplementation
dart
static const int NUM_WEST = 37;NUM_ZERO ​
const int NUM_ZEROImplementation
dart
static const int NUM_ZERO = 96;NUMLOCK ​
const int NUMLOCKImplementation
dart
static const int NUMLOCK = 144;O ​
const int OImplementation
dart
static const int O = 79;ONE ​
const int ONEImplementation
dart
static const int ONE = 49;OPEN_SQUARE_BRACKET ​
const int OPEN_SQUARE_BRACKETCAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int OPEN_SQUARE_BRACKET = 219;P ​
const int PImplementation
dart
static const int P = 80;PAGE_DOWN ​
const int PAGE_DOWNImplementation
dart
static const int PAGE_DOWN = 34;PAGE_UP ​
const int PAGE_UPImplementation
dart
static const int PAGE_UP = 33;PAUSE ​
const int PAUSEImplementation
dart
static const int PAUSE = 19;PERIOD ​
const int PERIODCAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int PERIOD = 190;PRINT_SCREEN ​
const int PRINT_SCREENImplementation
dart
static const int PRINT_SCREEN = 44;Q ​
const int QImplementation
dart
static const int Q = 81;QUESTION_MARK ​
const int QUESTION_MARKCAUTION: The question mark is for US-keyboard layouts. It varies for other locales and keyboard layouts.
Implementation
dart
static const int QUESTION_MARK = 63;R ​
const int RImplementation
dart
static const int R = 82;RIGHT ​
const int RIGHTImplementation
dart
static const int RIGHT = 39;S ​
const int SImplementation
dart
static const int S = 83;SCROLL_LOCK ​
const int SCROLL_LOCKImplementation
dart
static const int SCROLL_LOCK = 145;SEMICOLON ​
const int SEMICOLONCAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int SEMICOLON = 186;SEVEN ​
const int SEVENImplementation
dart
static const int SEVEN = 55;SHIFT ​
const int SHIFTImplementation
dart
static const int SHIFT = 16;SINGLE_QUOTE ​
const int SINGLE_QUOTECAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int SINGLE_QUOTE = 222;SIX ​
const int SIXImplementation
dart
static const int SIX = 54;SLASH ​
const int SLASHCAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int SLASH = 191;SPACE ​
const int SPACEImplementation
dart
static const int SPACE = 32;T ​
const int TImplementation
dart
static const int T = 84;TAB ​
const int TABImplementation
dart
static const int TAB = 9;THREE ​
const int THREEImplementation
dart
static const int THREE = 51;TILDE ​
const int TILDECAUTION: This constant requires localization for other locales and keyboard layouts.
Implementation
dart
static const int TILDE = 192;TWO ​
const int TWOImplementation
dart
static const int TWO = 50;U ​
const int UImplementation
dart
static const int U = 85;UNKNOWN ​
const int UNKNOWNA sentinel value if the keycode could not be determined.
Implementation
dart
static const int UNKNOWN = -1;UP ​
const int UPImplementation
dart
static const int UP = 38;V ​
const int VImplementation
dart
static const int V = 86;W ​
const int WImplementation
dart
static const int W = 87;WIN_IME ​
const int WIN_IMEImplementation
dart
static const int WIN_IME = 229;WIN_KEY ​
const int WIN_KEYImplementation
dart
static const int WIN_KEY = 224;WIN_KEY_FF_LINUX ​
const int WIN_KEY_FF_LINUXImplementation
dart
static const int WIN_KEY_FF_LINUX = 0;WIN_KEY_LEFT ​
const int WIN_KEY_LEFTImplementation
dart
static const int WIN_KEY_LEFT = 91;WIN_KEY_RIGHT ​
const int WIN_KEY_RIGHTImplementation
dart
static const int WIN_KEY_RIGHT = 92;X ​
const int XImplementation
dart
static const int X = 88;Y ​
const int YImplementation
dart
static const int Y = 89;Z ​
const int ZImplementation
dart
static const int Z = 90;ZERO ​
const int ZEROImplementation
dart
static const int ZERO = 48;