1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "core/event/key_event.h"
17
18 namespace OHOS::Ace {
19
20 namespace {
21
22 // key : define aosp key event code, value : define ace key string
23 constexpr int32_t KEYCODE_SIZE = 289;
24 const char* g_aospKeycode2String[KEYCODE_SIZE] = {
25 "Unknown", "SoftLeft", "SoftRight", "Home", "Back", "Call", "EndCall", "Digit0", "Digit1", "Digit2", "Digit3",
26 "Digit4", "Digit5", "Digit6", "Digit7", "Digit8", "Digit9", "Star", "Pound", "DpadUp", "DpadDown", "DpadLeft",
27 "DpadRight", "DpadCenter", "VolumeUp", "VolumeDown", "Power", "Camera", "Clear", "KeyA", "KeyB", "KeyC",
28 "KeyD", "KeyE", "KeyF", "KeyG", "KeyH", "KeyI", "KeyJ", "KeyK", "KeyL", "KeyM", "KeyN", "KeyO", "KeyP",
29 "KeyQ", "KeyR", "KeyS", "KeyT", "KeyU", "KeyV", "KeyW", "KeyX", "KeyY", "KeyZ", "Comma", "Period", "AltLeft",
30 "AltRight", "ShiftLeft", "ShiftRight", "Tab", "Space", "Sym", "Explorer", "Envelope", "Enter", "Del", "Grave",
31 "Minus", "Equals", "LeftBracket", "RightBracket", "BackSlash", "Semicolon", "Apostrophe", "Slash", "At",
32 "Num", "HeadsetHook", "Focus", "Plus", "Menu", "Notification", "Search", "MeidaPlayPause",
33 "MeidaStop", "MeidaNext", "MeidaPrevious", "MeidaRewind", "MeidaFastForward", "Mute", "PageUp", "PageDown",
34 "PictSymbols", "SwitchCharset", "ButtonA", "ButtonB", "ButtonC", "ButtonX", "ButtonY", "ButtonZ", "ButtonL1",
35 "ButtonR1", "ButtonL2", "ButtonR2", "ButtonThumbl", "ButtonThumbr", "ButtonStart", "ButtonSelect", "ButtonMode",
36 "Escape", "ForwardDel", "CtrlLeft", "CtrlRight", "CapsLock", "ScrollLock", "MetaLeft", "MetaRight", "Function",
37 "SysRq", "Break", "MoveHome", "MoveEnd", "Insert", "Forward", "MediaPlay", "MediaPause", "MediaClose",
38 "MediaReject", "MediaRecord", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "NumLock",
39 "Numpad0", "Numpad1", "Numpad2", "Numpad3", "Numpad4", "Numpad5", "Numpad6", "Numpad7", "Numpad8", "NumPad9",
40 "NumpadDivide", "NumpadMultiply", "NumpadSubtract", "NumpadAdd", "NumpadDot", "NumpadComma", "NumpadEnter",
41 "NumpadEquals", "NumpadLeftParen", "NumpadRightParen", "VolumeMute", "Info", "ChannelUp", "ChannelDown", "ZoomIn",
42 "ZoomOut", "Tv", "Window", "Guide", "Dvr", "BookMark", "Captions", "Settings", "TvPower", "TvInput", "StbPower",
43 "StbInput", "AvrPower", "AvrInput", "ProgRed", "ProgGreen", "ProgYellow", "ProgBlue", "AppSwitch", "Button1",
44 "Button2", "Button3", "Button4", "Button5", "Button6", "Button7", "Button8", "Button9", "Button10", "Button11",
45 "Button12", "Button13", "Button14", "Button15", "Button16", "LanguageSwitch", "MannerMode", "3DMode", "Contacts",
46 "Calendar", "Music", "Calculator", "ZenkakuHankaku", "Eisu", "Muhenkan", "Henkan", "KatakanaHiragana", "Yen", "Ro",
47 "Kana", "Assist", "BrightnessDown", "BrightnessUp", "MediaAudioTrack", "Sleep", "WakeUp", "Pairing", "MediaTopMenu",
48 "Digit11", "Digit12", "LastChannel", "TvDataService", "VoiceAssist", "TvRadioService", "TvTeletext",
49 "TvNumberEntry", "TvTerrestrialAnalog", "TvTerrestrialDigital", "TvSatellite", "TvSatelliteBS", "TvSatelliteCS",
50 "TvSatelliteService", "TvNetWork", "TvAntennaCable", "TvInputHdmi1", "TvInputHdmi2", "TvInputHdmi3", "TvInputHdmi4",
51 "TvInputComposite1", "TvInputComposite2", "TvInputComponent1", "TvInputComponent2", "TvInputVGA1",
52 "TvAudioDescription", "TvAudioDescriptionMixUp", "TvAudioDescriptionMixDown", "TvZoomMode", "TvContentsMenu",
53 "TvMediaContextMenu", "TvTimerProgramming", "Help", "NavigatePrevious", "NavigateNext", "NavigateIn", "NavigateOut",
54 "StemPrimary", "Stem1", "Stem2", "Stem3", "DpadUpLeft", "DpadDownLeft", "DpadUpRight", "DpadDownRight",
55 "MediaSkipForward", "MediaSkipBackward", "MediaStepForward", "MediaStepBackward", "SoftSleep", "Cut", "Copy",
56 "Paste", "SystemNavigationUp", "SystemNavigationDown", "SystemNavigationLeft", "SystemNavigationRight", "AllApps",
57 "Refresh", "ThumbsUp", "ThumbsDown", "ProfileSwitch"
58 };
59
60 } // namespace
61
KeyToString(int32_t code)62 const char* KeyToString(int32_t code)
63 {
64 if (code >= 0 && code < KEYCODE_SIZE) {
65 return g_aospKeycode2String[code];
66 } else {
67 return g_aospKeycode2String[0]; // "UnKnown"
68 }
69 }
70
71 } // namespace OHOS::Ace