• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "mock_key_event.h"
17 
18 namespace OHOS {
19 namespace MMI {
20 const int32_t KeyEvent::KEYCODE_UNKNOWN = -1;
21 const int32_t KeyEvent::KEYCODE_VOLUME_UP = 16;
22 const int32_t KeyEvent::KEYCODE_VOLUME_DOWN = 17;
23 const int32_t KeyEvent::KEYCODE_POWER = 18;
24 const int32_t KeyEvent::KEY_ACTION_UNKNOWN = 0X00000000;
25 const int32_t KeyEvent::KEY_ACTION_CANCEL = 0X00000001;
26 const int32_t KeyEvent::KEY_ACTION_DOWN = 0x00000002;
27 const int32_t KeyEvent::KEY_ACTION_UP = 0X00000003;
28 const int32_t KeyEvent::KEYCODE_NUMPAD_1 = 2104;
29 const int32_t KeyEvent::KEYCODE_NUMPAD_2 = 2105;
30 const int32_t KeyEvent::KEYCODE_NUMPAD_3 = 2106;
31 const int32_t KeyEvent::KEYCODE_NUMPAD_4 = 2107;
32 const int32_t KeyEvent::KEYCODE_NUMPAD_5 = 2108;
33 const int32_t KeyEvent::KEYCODE_NUMPAD_6 = 2109;
34 const int32_t KeyEvent::KEYCODE_NUMPAD_7 = 2110;
35 const int32_t KeyEvent::KEYCODE_NUMPAD_8 = 2111;
36 const int32_t KeyEvent::KEYCODE_NUMPAD_9 = 2112;
37 const int32_t KeyEvent::KEYCODE_NUMPAD_DIVIDE = 2113;
38 const int32_t KeyEvent::KEYCODE_NUMPAD_MULTIPLY = 2114;
39 const int32_t KeyEvent::KEYCODE_NUMPAD_SUBTRACT = 2115;
40 const int32_t KeyEvent::KEYCODE_NUMPAD_ADD = 2116;
41 const int32_t KeyEvent::KEYCODE_SHIFT_LEFT = 2047;
42 const int32_t KeyEvent::KEYCODE_SHIFT_RIGHT = 2048;
43 const int32_t KeyEvent::KEYCODE_CTRL_LEFT = 2072;
44 const int32_t KeyEvent::KEYCODE_CTRL_RIGHT = 2073;
45 
KeyItem()46 KeyEvent::KeyItem::KeyItem()
47 {}
48 
~KeyItem()49 KeyEvent::KeyItem::~KeyItem()
50 {}
51 
GetKeyCode() const52 int32_t KeyEvent::KeyItem::GetKeyCode() const
53 {
54     return keyCode_;
55 }
56 
SetKeyCode(int32_t keyCode)57 void KeyEvent::KeyItem::SetKeyCode(int32_t keyCode)
58 {
59     keyCode_ = keyCode;
60 }
61 
GetDownTime() const62 int64_t KeyEvent::KeyItem::GetDownTime() const
63 {
64     return downTime_;
65 }
66 
SetDownTime(int64_t downTime)67 void KeyEvent::KeyItem::SetDownTime(int64_t downTime)
68 {
69     downTime_ = downTime;
70 }
71 
GetDeviceId() const72 int32_t KeyEvent::KeyItem::GetDeviceId() const
73 {
74     return deviceId_;
75 }
76 
SetDeviceId(int32_t deviceId)77 void KeyEvent::KeyItem::SetDeviceId(int32_t deviceId)
78 {
79     deviceId_ = deviceId;
80 }
81 
IsPressed() const82 bool KeyEvent::KeyItem::IsPressed() const
83 {
84     return pressed_;
85 }
86 
SetPressed(bool pressed)87 void KeyEvent::KeyItem::SetPressed(bool pressed)
88 {
89     pressed_ = pressed;
90 }
91 
KeyEvent(int32_t eventType)92 KeyEvent::KeyEvent(int32_t eventType) : InputEvent(eventType)
93 {}
94 
KeyEvent(const KeyEvent & other)95 KeyEvent::KeyEvent(const KeyEvent& other)
96     : InputEvent(other), keyCode_(other.keyCode_), keys_(other.keys_), keyAction_(other.keyAction_)
97 {}
98 
~KeyEvent()99 KeyEvent::~KeyEvent()
100 {}
101 
Create()102 std::shared_ptr<KeyEvent> KeyEvent::Create()
103 {
104     return std::shared_ptr<KeyEvent>(new KeyEvent(InputEvent::EVENT_TYPE_KEY));
105 }
106 
AddKeyItem(const KeyItem & keyItem)107 void KeyEvent::AddKeyItem(const KeyItem& keyItem)
108 {
109     keys_.push_back(keyItem);
110 }
111 
GetKeyCode() const112 int32_t KeyEvent::GetKeyCode() const
113 {
114     return keyCode_;
115 }
116 
SetKeyCode(int32_t keyCode)117 void KeyEvent::SetKeyCode(int32_t keyCode)
118 {
119     keyCode_ = keyCode;
120 }
121 
WriteToParcel(Parcel & out) const122 bool KeyEvent::WriteToParcel(Parcel& out) const
123 {
124     return true;
125 }
126 
ReadFromParcel(Parcel & in)127 bool KeyEvent::ReadFromParcel(Parcel& in)
128 {
129     return true;
130 }
131 
GetPressedKeys() const132 std::vector<int32_t> KeyEvent::GetPressedKeys() const
133 {
134     std::vector<int32_t> result;
135     for (const auto &item : keys_) {
136         if (item.IsPressed()) {
137             result.push_back(item.GetKeyCode());
138         }
139     }
140     return result;
141 }
142 
GetKeyAction() const143 int32_t KeyEvent::GetKeyAction() const
144 {
145     return keyAction_;
146 }
147 } // namespace MMI
148 } // namespace OHOS