Untitled - MARKUP 2.87 KB
                                
                                    import com.github.kwhat.jnativehook.GlobalScreen
import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent
import com.github.kwhat.jnativehook.keyboard.NativeKeyListener
import java.awt.Point
import java.awt.Robot
import java.awt.event.InputEvent
import kotlin.system.exitProcess


val robot = Robot().apply {
    autoDelay = 210
}

val area = buildList {
    add(listOf(0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0))
    add(listOf(1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0))
    add(listOf(1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0))
    add(listOf(1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0))
    add(listOf(1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0))
    add(listOf(1, 1, 1, 1, 1, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0))
    add(listOf(1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0))
    add(listOf(1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0))
    add(listOf(1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0))
    add(listOf(1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0))
    add(listOf(1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
}

fun main() {
    GlobalScreen.registerNativeHook();
    GlobalScreen.addNativeKeyListener(GlobalKeyListenerExample())

    val fishingRod = Point(-952, 540)

    val corner = Point(-1484, 102)
    val offset = Point(74, 74)

    val points = area.mapIndexed { offsetY, row ->
        row.mapIndexed { offsetX, value ->
            when(value) {
                1 -> Point(
                    corner.x + offsetX * offset.x,
                    corner.y + offsetY * offset.y
                )
                else -> null
            }
        }
    }
    .flatten()
    .filterNotNull()

    var clickCounter = 0

    for(i in 0 .. 10 ) {
        points
            .shuffled()
            .forEach {
                System.out.println("Click counter: ${clickCounter++}")
                rightClick(fishingRod.x, fishingRod.y)
                leftClick(it.x, it.y)
            }
    }
}

private fun leftClick(x: Int, y: Int) {
    mouseClick(InputEvent.BUTTON1_DOWN_MASK, x, y)
}

private fun rightClick(x: Int, y: Int) {
    mouseClick(InputEvent.BUTTON3_DOWN_MASK, x, y)
}

private fun mouseClick(button: Int, x: Int, y: Int) {
    robot.mouseMove(x, y)

    robot.mousePress(button)
    robot.mouseRelease(button)
}


class GlobalKeyListenerExample : NativeKeyListener {
    override fun nativeKeyPressed(e: NativeKeyEvent) {
        println("Key Pressed: " + NativeKeyEvent.getKeyText(e.keyCode))
        exitProcess(1)
    }

    override fun nativeKeyReleased(e: NativeKeyEvent) {
        println("Key Released: " + NativeKeyEvent.getKeyText(e.keyCode))
    }

    override fun nativeKeyTyped(e: NativeKeyEvent) {
        println("Key Typed: " + NativeKeyEvent.getKeyText(e.keyCode))
    }
}
                                
                            

Paste Hosted With By Wklejamy.pl