libaurum: add REPEAT to sendKey command 52/281452/10 accepted/tizen_7.0_unified_hotfix tizen_7.0_hotfix accepted/tizen/7.0/unified/hotfix/20221116.105913 accepted/tizen/unified/20220922.114019 tizen_7.0_m2_release
authorChihun Jeong <chihun.jeong@samsung.com>
Thu, 22 Sep 2022 02:06:25 +0000 (11:06 +0900)
committerwoochan lee <wc0917.lee@samsung.com>
Thu, 22 Sep 2022 02:10:04 +0000 (02:10 +0000)
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

libaurum/inc/Impl/MockDeviceImpl.h
libaurum/inc/Impl/TizenDeviceImpl.h
libaurum/inc/Interface/IDevice.h
libaurum/inc/UiDevice.h
libaurum/src/Impl/MockDeviceImpl.cc
libaurum/src/Impl/TizenDeviceImpl.cc
libaurum/src/UiDevice.cc
org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc
org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc
protocol/aurum.proto

index 41e2cd19966a5a5b5c184d825a21be45491981d4..e7ef2cef72d66172abee697d8ba1616eb290fe6b 100644 (file)
@@ -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
index 253685ba11fb345875c1f3df0000ed6d3280676d..1dd946c31c11aa3c5fba4c80201d13782443fdb1 100644 (file)
@@ -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;
index 640406033dd4eb0c9dfa8d598ef9805356cd671c..23058c6d82fc9b19946a1b3eb8038f1dc0db8bf2 100644 (file)
@@ -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.
      *
index 05f7c014efff999cfeb33a2efad2b9bd52bb2c01..7e89949c1c6877dfad1895576b4e2b3bcb67c7ee 100644 (file)
@@ -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.
      *
index 629329cedd3ed0efee91006a0694944073260f3c..4820f112851bd33218917cfc503f74b0ce45e90b 100644 (file)
@@ -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;
index ab87c4a90488f108cd509e7dab4398251382f5b8..9fa7e5972276db088e9fdc16aebeaa4cb44255ce 100644 (file)
@@ -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;
 }
index a25b1cd87c65e9bf46852aad449dea8d269f0abe..198dcd84c3008fc8747614e69d344f8983c81b10 100644 (file)
@@ -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);
index 477ab5e0ed34c6feb381aab0459d32f398771608..ca19a75871b4d8062065ab5aa231be172fb82f13 100644 (file)
@@ -288,4 +288,3 @@ aurumServiceImpl::~aurumServiceImpl()
     std::unique_ptr<GetTextMinBoundingRectCommand> cmd = std::make_unique<GetTextMinBoundingRectCommand>(request, response);
     return execute(cmd.get(), true);
 }
-
index 135f263ed5ac9cdb3d2e783480248f75c4cfd570..150c0724272521738b19639408934910b9e16499 100644 (file)
@@ -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
index 9b00b62fbffa963f8ffe7e3e819785b6123ac107..d1a76963a1b74b1e3c65e88cea6127478805c2f3 100644 (file)
@@ -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;
 }
-