diff --git a/src/main/kotlin/com/waicool20/kaga/util/LockPreventer.kt b/src/main/kotlin/com/waicool20/kaga/util/LockPreventer.kt index 3e19d45..818c30a 100644 --- a/src/main/kotlin/com/waicool20/kaga/util/LockPreventer.kt +++ b/src/main/kotlin/com/waicool20/kaga/util/LockPreventer.kt @@ -23,22 +23,19 @@ package com.waicool20.kaga.util import java.awt.Robot import java.awt.event.KeyEvent import java.util.* +import kotlin.concurrent.timerTask class LockPreventer { - private var timer: Timer? = null - private val robot = Robot() - private val timerTask = object : TimerTask() { - override fun run() { + private val timer by lazy { Timer() } + private val robot by lazy { Robot() } + private val task by lazy { + timerTask { robot.keyPress(KeyEvent.VK_SHIFT) Thread.sleep(10) robot.keyRelease(KeyEvent.VK_SHIFT) } } - fun start() { - timer = Timer() - timer?.schedule(timerTask, 0L, 60 * 1000L) - } - - fun stop() = timer?.cancel() + fun start() = timer.schedule(task, 0L, 60 * 1000L) + fun stop() = task.cancel() }