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 "keyboard_event.h" 17 18 #include <global.h> 19 #include <memory> 20 21 #include "global.h" 22 #include "input_event_callback.h" 23 #include "key_event.h" 24 25 namespace OHOS { 26 namespace MiscServices { 27 using namespace MMI; 28 GetInstance()29KeyboardEvent &KeyboardEvent::GetInstance() 30 { 31 static KeyboardEvent keyboardEvent; 32 return keyboardEvent; 33 } 34 AddKeyEventMonitor(KeyHandle handle)35int32_t KeyboardEvent::AddKeyEventMonitor(KeyHandle handle) 36 { 37 IMSA_HILOGI("KeyboardEvent::AddKeyEventMonitor"); 38 std::shared_ptr<InputEventCallback> callback = std::make_shared<InputEventCallback>(); 39 callback->SetKeyHandle(handle); 40 int32_t monitorId = 41 InputManager::GetInstance()->AddMonitor(std::static_pointer_cast<MMI::IInputEventConsumer>(callback)); 42 if (monitorId < 0) { 43 IMSA_HILOGE("add monitor failed, id: %{public}d", monitorId); 44 return ErrorCode::ERROR_SUBSCRIBE_KEYBOARD_EVENT; 45 } 46 IMSA_HILOGD("add monitor success, id: %{public}d", monitorId); 47 return ErrorCode::NO_ERROR; 48 } 49 } // namespace MiscServices 50 } // namespace OHOS 51