From 08396676d2d9a39e2083761afc3fc9389cd63d8a Mon Sep 17 00:00:00 2001 From: "vladislav.shishov" Date: Tue, 28 Jan 2025 17:31:06 +0200 Subject: [PATCH] [remote-driver] RemoteKeyboard#pressing : release pressed key in case of exception GitOrigin-RevId: ba37300f1f50b008dfc7f33663c4aa4c7290d007 --- .../driver/sdk/ui/keyboard/RemoteKeyboard.kt | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/platform/remote-driver/test-sdk/src/com/intellij/driver/sdk/ui/keyboard/RemoteKeyboard.kt b/platform/remote-driver/test-sdk/src/com/intellij/driver/sdk/ui/keyboard/RemoteKeyboard.kt index 87e761bb29dd..847f88328bf5 100644 --- a/platform/remote-driver/test-sdk/src/com/intellij/driver/sdk/ui/keyboard/RemoteKeyboard.kt +++ b/platform/remote-driver/test-sdk/src/com/intellij/driver/sdk/ui/keyboard/RemoteKeyboard.kt @@ -9,47 +9,56 @@ class RemoteKeyboard(private val robot: Robot) { private val LOG get() = logger() } + fun key(key: Int) = robot.pressAndReleaseKey(key) fun enter() { LOG.info("Pressing enter") key(KeyEvent.VK_ENTER) } + fun escape() { LOG.info("Pressing escape") key(KeyEvent.VK_ESCAPE) } + fun down() { LOG.info("Pressing down") key(KeyEvent.VK_DOWN) } + fun up() { LOG.info("Pressing up") key(KeyEvent.VK_UP) } + fun left() { LOG.info("Pressing left") key(KeyEvent.VK_LEFT) } + fun right() { LOG.info("Pressing right") key(KeyEvent.VK_RIGHT) } + fun backspace() { LOG.info("Pressing backspace") key(KeyEvent.VK_BACK_SPACE) } + fun tab() { LOG.info("Pressing tab") key(KeyEvent.VK_TAB) } + fun space() { LOG.info("Pressing space") key(KeyEvent.VK_SPACE) } fun hotKey(vararg keyCodes: Int) { - LOG.info("Pressing hotkeys ${keyCodes.joinToString(",") {"'$it'"}}.") + LOG.info("Pressing hotkeys ${keyCodes.joinToString(",") { "'$it'" }}.") val lastKey = keyCodes.last() val others = keyCodes.dropLast(1) @@ -75,9 +84,13 @@ class RemoteKeyboard(private val robot: Robot) { fun pressing(key: Int, doWhilePress: RemoteKeyboard.() -> Unit) { LOG.info("Performing action while pressing $key.") - robot.pressKey(key) - this.doWhilePress() - robot.releaseKey(key) + try { + robot.pressKey(key) + this.doWhilePress() + } + finally { + robot.releaseKey(key) + } } fun doublePressing(key: Int, doWhilePress: RemoteKeyboard.() -> Unit) { @@ -86,7 +99,8 @@ class RemoteKeyboard(private val robot: Robot) { try { robot.doublePressKeyAndHold(key) this.doWhilePress() - } finally { + } + finally { robot.releaseKey(key) } }