com.github.bloodshura.ignitium.ntv.keyboard.AbstractKeyboardWatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ignitium-native Show documentation
Show all versions of ignitium-native Show documentation
An API for working with native system APIs, with a higher-level interface.
The newest version!
package com.github.bloodshura.ignitium.ntv.keyboard;
import com.github.bloodshura.ignitium.collection.list.XList;
import com.github.bloodshura.ignitium.collection.list.impl.XArrayList;
import com.github.bloodshura.ignitium.collection.view.XBasicView;
import com.github.bloodshura.ignitium.collection.view.XView;
import com.github.bloodshura.ignitium.input.Key;
import com.github.bloodshura.ignitium.input.KeyListener;
import com.github.bloodshura.ignitium.ntv.NativeException;
import javax.annotation.Nonnull;
public abstract class AbstractKeyboardWatcher implements KeyboardWatcher {
protected final XList pressedKeys;
private final XList hooks;
private long lastPollMillis;
private final KeyboardMapping mapping;
public AbstractKeyboardWatcher(@Nonnull KeyboardMapping mapping) throws NativeException {
this.hooks = new XArrayList<>();
this.mapping = mapping;
this.pressedKeys = new XArrayList<>();
pressedKeys.addInsertionListener(key -> getHooks().forEach(hook -> hook.keyPressed(key)));
pressedKeys.addRemovalListener(key -> getHooks().forEach(hook -> hook.keyReleased(key)));
}
@Override
public void dispose() throws NativeException {
hooks.clear();
pressedKeys.clear();
}
@Nonnull
@Override
public final XList getHooks() {
return hooks;
}
@Nonnull
public KeyboardMapping getMapping() {
return mapping;
}
@Nonnull
@Override
public final XView getPressedKeys() {
return new XBasicView<>(pressedKeys);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy