From: Chihun Jeong Date: Thu, 22 Sep 2022 02:06:25 +0000 (+0900) Subject: libaurum: add REPEAT to sendKey command X-Git-Tag: accepted/tizen/unified/20220922.114019^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6c56e619ba3f0ffea46c2f0595c0e2018059f57d;p=platform%2Fcore%2Fuifw%2Faurum.git libaurum: add REPEAT to sendKey command This command simulates repeat press of the given key. How to use Sends Right key every 100ms for a total of 2000ms: stub.sendKey(ReqKey(type='XF86', actionType='REPEAT', XF86keyCode='Right', durationMs=2000, intervalMs=100)) Change-Id: I03ec7a8b79a28d6802fac5318a333e7ff5cbda59 --- diff --git a/libaurum/inc/Impl/MockDeviceImpl.h b/libaurum/inc/Impl/MockDeviceImpl.h index 41e2cd1..e7ef2ce 100644 --- a/libaurum/inc/Impl/MockDeviceImpl.h +++ b/libaurum/inc/Impl/MockDeviceImpl.h @@ -149,6 +149,12 @@ public: */ bool pressKeyCode(std::string keycode, KeyRequestType type) override; + /** + * @brief TBD + * @since_tizen 7.0 + */ + bool repeatKeyCode(std::string keycode, int intervalMs, int durationMs) override; + /** * @brief TBD * @since_tizen 6.5 diff --git a/libaurum/inc/Impl/TizenDeviceImpl.h b/libaurum/inc/Impl/TizenDeviceImpl.h index 253685b..1dd946c 100644 --- a/libaurum/inc/Impl/TizenDeviceImpl.h +++ b/libaurum/inc/Impl/TizenDeviceImpl.h @@ -111,6 +111,11 @@ public: */ bool pressKeyCode(std::string keycode, KeyRequestType type) override; + /** + * @copydoc IDevice::repeatKeyCode() + */ + bool repeatKeyCode(std::string keycode, int intervalMs, int durationMs) override; + /** * @copydoc IDevice::takeScreenshot() */ @@ -191,7 +196,9 @@ private: static const int INTV_MINIMUM_DRAG_MS = 25; static const int INTV_MINIMUM_USLEEP = 1000; static const int MINIMUM_DURATION_DRAG = 100; + static const int MINIMUM_REPEAT_INTERVAL = 20; static const unsigned int MSEC_PER_SEC = 1000; + static const unsigned int USEC_PER_MSEC = 1000; static const unsigned int MAX_FINGER_NUMBER = 2; struct timespec tStart; bool isTimerStarted; diff --git a/libaurum/inc/Interface/IDevice.h b/libaurum/inc/Interface/IDevice.h index 6404060..23058c6 100644 --- a/libaurum/inc/Interface/IDevice.h +++ b/libaurum/inc/Interface/IDevice.h @@ -44,6 +44,7 @@ enum class KeyRequestType { LONG_STROKE, //Key long press(2000ms) and release PRESS, //Key press RELEASE, //Key release + REPEAT, //Repeat key press(100ms) and release }; /** @@ -244,6 +245,19 @@ public: */ virtual bool pressKeyCode(std::string keycode, KeyRequestType type) = 0; + /** + * @brief Simulates repeat press of the given keycode key. + * + * @param[in] keycode keycode + * @param[in] intervalMs time interval for pressing given keycode key + * @param[in] durationMs total time to press given keycode key + * + * @return true if the scroll keycode succeeded else false + * + * @since_tizen 7.0 + */ + virtual bool repeatKeyCode(std::string keycode, int intervalMs, int durationMs) = 0; + /** * @brief Take a screenshot of current window and store it as image file. * diff --git a/libaurum/inc/UiDevice.h b/libaurum/inc/UiDevice.h index 05f7c01..7e89949 100644 --- a/libaurum/inc/UiDevice.h +++ b/libaurum/inc/UiDevice.h @@ -236,6 +236,19 @@ public: */ bool pressKeyCode(std::string keycode, KeyRequestType type) override; + /** + * @brief Simulates repeat press of the given keycode key. + * + * @param[in] keycode keycode + * @param[in] intervalMs time interval for pressing given keycode key + * @param[in] durationMs total time to press given keycode key + * + * @return true if the scroll keycode succeeded else false + * + * @since_tizen 7.0 + */ + bool repeatKeyCode(std::string keycode, int intervalMs, int durationMs) override; + /** * @brief Take a screenshot of current window and store it as image file. * diff --git a/libaurum/src/Impl/MockDeviceImpl.cc b/libaurum/src/Impl/MockDeviceImpl.cc index 629329c..4820f11 100644 --- a/libaurum/src/Impl/MockDeviceImpl.cc +++ b/libaurum/src/Impl/MockDeviceImpl.cc @@ -190,6 +190,11 @@ bool MockDeviceImpl::pressKeyCode(std::string keycode, KeyRequestType type) return true; } +bool MockDeviceImpl::repeatKeyCode(std::string keycode, int intervalMs, int durationMs) +{ + return false; +} + bool MockDeviceImpl::takeScreenshot(std::string path, float scale, int quality) { return true; diff --git a/libaurum/src/Impl/TizenDeviceImpl.cc b/libaurum/src/Impl/TizenDeviceImpl.cc index ab87c4a..9fa7e59 100644 --- a/libaurum/src/Impl/TizenDeviceImpl.cc +++ b/libaurum/src/Impl/TizenDeviceImpl.cc @@ -248,13 +248,39 @@ bool TizenDeviceImpl::pressKeyCode(std::string keycode, KeyRequestType type) return pressKeyCode(keycode); else if (type == KeyRequestType::RELEASE) return releaseKeyCode(keycode); + else if (type == KeyRequestType::REPEAT) + { + LOGI("You can't repeat non-XF86 keys"); + return false; + } + return false; } +bool TizenDeviceImpl::repeatKeyCode(std::string keycode, int intervalMs, int durationMs) +{ + if (intervalMs < MINIMUM_REPEAT_INTERVAL) + { + LOGI("Minimum intervalMs is %d, but user has set it to %d, so changed it to %d", MINIMUM_REPEAT_INTERVAL, intervalMs, MINIMUM_REPEAT_INTERVAL); + intervalMs = MINIMUM_REPEAT_INTERVAL; + } + + int press_count = durationMs / intervalMs; + + for (int i = 0; i < press_count; i++) + { + strokeKeyCode(keycode, INTV_SHORTSTROKE); + usleep((intervalMs - INTV_SHORTSTROKE) * USEC_PER_MSEC); + } + strokeKeyCode(keycode, INTV_SHORTSTROKE); + + return true; +} + bool TizenDeviceImpl::strokeKeyCode(std::string keycode, unsigned int durationMs) { pressKeyCode(keycode); - usleep(durationMs * 1000); + usleep(durationMs * USEC_PER_MSEC); releaseKeyCode(keycode); return true; } diff --git a/libaurum/src/UiDevice.cc b/libaurum/src/UiDevice.cc index a25b1cd..198dcd8 100644 --- a/libaurum/src/UiDevice.cc +++ b/libaurum/src/UiDevice.cc @@ -420,6 +420,12 @@ bool UiDevice::pressKeyCode(std::string keycode, KeyRequestType type) return result; } +bool UiDevice::repeatKeyCode(std::string keycode, int intervalMs, int durationMs) +{ + bool result = mDeviceImpl->repeatKeyCode(keycode, intervalMs, durationMs); + return result; +} + bool UiDevice::takeScreenshot(std::string path, float scale, int quality) { return mDeviceImpl->takeScreenshot(path, scale, quality); diff --git a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc index 477ab5e..ca19a75 100644 --- a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc +++ b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc @@ -288,4 +288,3 @@ aurumServiceImpl::~aurumServiceImpl() std::unique_ptr cmd = std::make_unique(request, response); return execute(cmd.get(), true); } - diff --git a/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc index 135f263..150c072 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc @@ -49,8 +49,18 @@ SendKeyCommand::SendKeyCommand(const ::aurum::ReqKey *request, mDevice->wheelUp(1, 167); else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_WHEELDOWN) mDevice->wheelDown(1, 167); - else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_XF86) { - mDevice->pressKeyCode(mRequest->xf86keycode(), actionType); + else if (type == ::aurum::ReqKey_KeyType::ReqKey_KeyType_XF86) + { + if (actionType == KeyRequestType::REPEAT) + { + int durationMs = mRequest->durationms(); + int intervalMs = mRequest->intervalms(); + mDevice->repeatKeyCode(mRequest->xf86keycode(), intervalMs, durationMs); + } + else + { + mDevice->pressKeyCode(mRequest->xf86keycode(), actionType); + } } return grpc::Status::OK; } \ No newline at end of file diff --git a/protocol/aurum.proto b/protocol/aurum.proto index 9b00b62..d1a7696 100644 --- a/protocol/aurum.proto +++ b/protocol/aurum.proto @@ -500,7 +500,6 @@ message ReqKey{ VOLUP = 3; VOLDOWN = 4; POWER = 5; - //KEY = 6; XF86 = 7; WHEELUP = 8; WHEELDOWN = 9; @@ -510,13 +509,13 @@ message ReqKey{ LONG_STROKE = 1; PRESS = 2; RELEASE = 3; + REPEAT = 4; } KeyType type = 1; KeyActionType actionType = 2; - //oneof keys { - //uint32 keyCode = 3; - string XF86keyCode = 4; - //} + string XF86keyCode = 3; + int32 durationMs = 4; + int32 intervalMs = 5; } message RspKey{ RspStatus status = 1; @@ -611,4 +610,3 @@ message RspGetTextMinBoundingRect { RspStatus status = 1; Rect size = 2; } -