All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.bloodshura.ignitium.ntv.mouse.AbstractMouseHandler Maven / Gradle / Ivy

The newest version!
package com.github.bloodshura.ignitium.ntv.mouse;

import com.github.bloodshura.ignitium.geometry.position.Position;
import com.github.bloodshura.ignitium.input.MouseButton;
import com.github.bloodshura.ignitium.ntv.NativeException;

import javax.annotation.Nonnull;
import java.awt.AWTException;
import java.awt.Robot;

public abstract class AbstractMouseHandler implements MouseHandler {
	private final Robot robot;

	public AbstractMouseHandler() throws NativeException {
		try {
			this.robot = new Robot();
		} catch (AWTException exception) {
			throw new NativeException("Could not instantiate an AWT Robot", exception);
		}
	}

	@Override
	public void press(@Nonnull MouseButton button) throws NativeException {
		robot.mousePress(button.getMask());
	}

	@Override
	public void release(@Nonnull MouseButton button) throws NativeException {
		robot.mouseRelease(button.getMask());
	}

	@Override
	public void setPosition(@Nonnull Position position) throws NativeException {
		robot.mouseMove((int) position.getX(), (int) position.getY());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy