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

com.github.bloodshura.ignitium.ntv.keyboard.CommonKeyboardHandler Maven / Gradle / Ivy

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

import com.github.bloodshura.ignitium.input.Key;
import com.github.bloodshura.ignitium.ntv.NativeException;

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

public class CommonKeyboardHandler implements KeyboardHandler {
	private final Robot robot;

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

	@Override
	public void dispose() throws NativeException {
	}

	@Override
	public void press(@Nonnull Key key) throws NativeException {
		robot.keyPress(key.getCode());
	}

	@Override
	public void release(@Nonnull Key key) throws NativeException {
		robot.keyRelease(key.getCode());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy