[remote-driver] RemoteKeyboard#pressing : release pressed key in case of exception

GitOrigin-RevId: ba37300f1f50b008dfc7f33663c4aa4c7290d007
This commit is contained in:
vladislav.shishov
2025-01-28 18:17:06 +00:00
committed by intellij-monorepo-bot
parent e961668bc2
commit 08396676d2
@@ -9,47 +9,56 @@ class RemoteKeyboard(private val robot: Robot) {
private val LOG
get() = logger<RemoteKeyboard>()
}
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)
}
}