diff --git a/etc/exceptional_system_keys_config.json b/etc/exceptional_system_keys_config.json index f677f0c28fd0745586f46ed263bc611284b0b7b1..e78ad25910c36df06059517dbe198fa5f3c85a3b 100644 --- a/etc/exceptional_system_keys_config.json +++ b/etc/exceptional_system_keys_config.json @@ -630,6 +630,18 @@ "longPressTime": 0, "triggerType": "up" }, + { + "preKeys": [], + "finalKey": 3221, + "longPressTime": 0, + "triggerType": "down" + }, + { + "preKeys": [], + "finalKey": 3221, + "longPressTime": 0, + "triggerType": "up" + }, { "preKeys": [], "finalKey": 4000, diff --git a/frameworks/proxy/events/src/key_event.cpp b/frameworks/proxy/events/src/key_event.cpp index e6dae4c889e300d1959279c6a38f4e3680f7c4c8..c80962b6cc425257894bd143136df5956f441462 100644 --- a/frameworks/proxy/events/src/key_event.cpp +++ b/frameworks/proxy/events/src/key_event.cpp @@ -425,6 +425,7 @@ const std::map KEYCODE_TO_STRING = { {KeyEvent::KEYCODE_KEY_PEN_AI, "KEYCODE_KEY_PEN_AI"}, {KeyEvent::KEYCODE_KEY_PEN_END_CLICK, "KEYCODE_KEY_PEN_END_CLICK"}, {KeyEvent::KEYCODE_KEY_PEN_END_DOUBLE_CLICK, "KEYCODE_KEY_PEN_END_DOUBLE_CLICK"}, + {KeyEvent::KEYCODE_KEY_PEN_MODE_SWITCH, "KEYCODE_KEY_PEN_MODE_SWITCH"}, {KeyEvent::KEYCODE_AOD_SLIDE_UNLOCK, "KEYCODE_AOD_SLIDE_UNLOCK"}, {KeyEvent::KEYCODE_RECENT, "KEYCODE_RECENT"}, {KeyEvent::KEYCODE_FLOATING_BACK, "KEYCODE_FLOATING_BACK"}, @@ -832,6 +833,7 @@ const int32_t KeyEvent::KEYCODE_KEY_PEN_END_CLICK = 3217; const int32_t KeyEvent::KEYCODE_KEY_PEN_END_DOUBLE_CLICK = 3218; const int32_t KeyEvent::KEYCODE_AOD_SLIDE_UNLOCK = 3219; const int32_t KeyEvent::KEYCODE_DIV = 3220; +const int32_t KeyEvent::KEYCODE_KEY_PEN_MODE_SWITCH = 3221; const int32_t KeyEvent::KEYCODE_REMOTE_POWER = 4000; const int32_t KeyEvent::KEYCODE_LEFT_KNOB_ROLL_UP = 10001; const int32_t KeyEvent::KEYCODE_LEFT_KNOB_ROLL_DOWN = 10002; diff --git a/frameworks/proxy/events/test/input_manager_test.cpp b/frameworks/proxy/events/test/input_manager_test.cpp index a2e65d70e93640e675ca6c6b74ae0c6526a378a4..49d49ac2e7250f3be7e741593d1545b6ca42c2c5 100644 --- a/frameworks/proxy/events/test/input_manager_test.cpp +++ b/frameworks/proxy/events/test/input_manager_test.cpp @@ -913,6 +913,51 @@ HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_12, TestSize.Level std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS)); } + +/** + * @tc.name: InputManagerTest_SubscribeKeyEvent_17 + * @tc.desc: Verify subscribe key event. + * @tc.type: FUNC + * @tc.require: + * @tc.author: + */ +HWTEST_F(InputManagerTest, InputManagerTest_SubscribeKeyEvent_17, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::set preKeys; + std::shared_ptr keyOption = std::make_shared(); + keyOption->SetPreKeys(preKeys); + keyOption->SetFinalKey(KeyEvent::KEYCODE_KEY_PEN_MODE_SWITCH); + keyOption->SetFinalKeyDown(true); + keyOption->SetFinalKeyDownDuration(0); + int32_t subscribeId = INVAID_VALUE; + subscribeId = InputManager::GetInstance()->SubscribeKeyEvent(keyOption, [](std::shared_ptr keyEvent) { + EventLogHelper::PrintEventData(keyEvent, MMI_LOG_HEADER); + MMI_HILOGD("[YKP] Subscribe key event KEYCODE_KEY_PEN_MODE_SWITCH down trigger callback"); + }); +#ifdef OHOS_BUILD_ENABLE_KEYBOARD + EXPECT_TRUE(subscribeId >= 0); +#else + EXPECT_TRUE(subscribeId < 0); +#endif // OHOS_BUILD_ENABLE_KEYBOARD + std::shared_ptr injectDownEvent = KeyEvent::Create(); + ASSERT_TRUE(injectDownEvent != nullptr); + int64_t downTime = GetNanoTime() / NANOSECOND_TO_MILLISECOND; + KeyEvent::KeyItem kitDown; + kitDown.SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_MODE_SWITCH); + kitDown.SetPressed(true); + kitDown.SetDownTime(downTime); + injectDownEvent->SetKeyCode(KeyEvent::KEYCODE_KEY_PEN_MODE_SWITCH); + injectDownEvent->SetKeyAction(KeyEvent::KEY_ACTION_DOWN); + injectDownEvent->AddPressedKeyItems(kitDown); + InputManager::GetInstance()->SimulateInputEvent(injectDownEvent); + ASSERT_EQ(injectDownEvent->GetKeyAction(), KeyEvent::KEY_ACTION_DOWN); + + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS)); + InputManager::GetInstance()->UnsubscribeKeyEvent(subscribeId); + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MILLISECONDS)); +} + /** * @tc.name: InputManagerTest_SubscribeKeyEvent_14 * @tc.desc: Verify subscribe key event. diff --git a/interfaces/native/innerkits/event/include/key_event.h b/interfaces/native/innerkits/event/include/key_event.h index 584756afaeee508f763f47b6ef403f502868b80f..0cfa43822f02867fde8f6199f0928a3706736a98 100644 --- a/interfaces/native/innerkits/event/include/key_event.h +++ b/interfaces/native/innerkits/event/include/key_event.h @@ -2802,6 +2802,13 @@ public: */ static const int32_t KEYCODE_KEY_PEN_END_DOUBLE_CLICK; + /** + * KEYCODE_PEN_AI + * + * @since 9 + */ + static const int32_t KEYCODE_KEY_PEN_MODE_SWITCH; + /** * Left Knob roll-up *

In contrast to {@link #static const int32_t KEYCODE_LEFT_KNOB_ROLL_DOWN}, diff --git a/service/event_handler/include/hos_key_event.h b/service/event_handler/include/hos_key_event.h index e93cbd4d54bdacb1e7585271cd0a69e9d2d4e3d7..7764c32b439697aac5c409a587ff34b4fb54b3f4 100644 --- a/service/event_handler/include/hos_key_event.h +++ b/service/event_handler/include/hos_key_event.h @@ -1331,6 +1331,7 @@ enum HosKeyEventEnum { HOS_KEY_PEN_END_DOUBLE_CLICK = 3218, HOS_KEYCODE_AOD_SLIDE_UNLOCK = 3219, HOS_KEY_DIV = 3220, + HOS_KEY_PEN_MODE_SWITCH = 3221, /** * Left Knob roll-up *

In contrast to {@link #KEY_LEFT_KNOB_ROLL_DOWN}, it means rolling the left knob upwards. The knob function diff --git a/service/event_handler/src/key_event_value_transformation.cpp b/service/event_handler/src/key_event_value_transformation.cpp index 957068ae4f6290da65ff6ee82b67a066b4ab78e6..d9b349d9ecc39dff91040b4e9616c8ba81662719 100644 --- a/service/event_handler/src/key_event_value_transformation.cpp +++ b/service/event_handler/src/key_event_value_transformation.cpp @@ -451,6 +451,7 @@ const std::multimap MAP_KEY_EVENT_VALUE_TR {754, {"KEY_PEN_AI", 754, 3216, HOS_KEY_PEN_AI}}, {755, {"KEY_PEN_END_CLICK", 755, 3217, HOS_KEY_PEN_END_CLICK}}, {756, {"KEY_PEN_END_DOUBLE_CLICK", 756, 3218, HOS_KEY_PEN_END_DOUBLE_CLICK}}, + {757, {"KEY_PEN_MODE_SWITCH", 757, 3221, HOS_KEY_PEN_MODE_SWITCH}}, {760, {"DAGGER_CLICK", 760, 3211, DAGGER_CLICK}}, {761, {"DAGGER_DOUBLE_CLICK", 761, 3212, DAGGER_DOUBLE_CLICK}}, {762, {"DAGGER_LONG_PRESS", 762, 3213, DAGGER_LONG_PRESS}}, diff --git a/service/subscriber/src/key_shortcut_manager.cpp b/service/subscriber/src/key_shortcut_manager.cpp index b529b4f5262a52504f760c0c55f6e22777192d05..4568fb168840ad242a9e142aa77a06cc6f0e6348 100644 --- a/service/subscriber/src/key_shortcut_manager.cpp +++ b/service/subscriber/src/key_shortcut_manager.cpp @@ -777,6 +777,7 @@ static const std::vector specialKeyCodes = { KeyEvent::KEYCODE_KEY_PEN_AI, KeyEvent::KEYCODE_KEY_PEN_END_CLICK, KeyEvent::KEYCODE_KEY_PEN_END_DOUBLE_CLICK, + KeyEvent::KEYCODE_KEY_PEN_MODE_SWITCH, KeyEvent::KEYCODE_REMOTE_POWER };