mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-26 17:55:14 +00:00
Add pasting support to the standalone emulator
- Move paste normalisation code to StringUtil, so it can be shared by emulators. - Add paste support to the emulator.
This commit is contained in:
@@ -8,6 +8,7 @@ import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
||||
import dan200.computercraft.core.apis.transfer.TransferredFile;
|
||||
import dan200.computercraft.core.apis.transfer.TransferredFiles;
|
||||
import dan200.computercraft.core.computer.Computer;
|
||||
import dan200.computercraft.core.util.StringUtil;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.glfw.GLFWDropCallback;
|
||||
import org.lwjgl.glfw.GLFWKeyCallbackI;
|
||||
@@ -54,16 +55,24 @@ public class InputState {
|
||||
}
|
||||
}
|
||||
|
||||
public void onKeyEvent(int key, int action, int modifiers) {
|
||||
public void onKeyEvent(long window, int key, int action, int modifiers) {
|
||||
switch (action) {
|
||||
case GLFW.GLFW_PRESS, GLFW.GLFW_REPEAT -> keyPressed(key, modifiers);
|
||||
case GLFW.GLFW_PRESS, GLFW.GLFW_REPEAT -> keyPressed(window, key, modifiers);
|
||||
case GLFW.GLFW_RELEASE -> keyReleased(key);
|
||||
}
|
||||
}
|
||||
|
||||
private void keyPressed(int key, int modifiers) {
|
||||
private void keyPressed(long window, int key, int modifiers) {
|
||||
if (key == GLFW.GLFW_KEY_ESCAPE) return;
|
||||
|
||||
if (key == GLFW.GLFW_KEY_V && modifiers == GLFW.GLFW_MOD_CONTROL) {
|
||||
var string = GLFW.glfwGetClipboardString(window);
|
||||
if (string != null) {
|
||||
var clipboard = StringUtil.normaliseClipboardString(string);
|
||||
if (!clipboard.isEmpty()) computer.queueEvent("paste", new Object[]{ clipboard });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ((modifiers & GLFW.GLFW_MOD_CONTROL) != 0) {
|
||||
switch (key) {
|
||||
|
||||
@@ -204,7 +204,7 @@ public class Main {
|
||||
}
|
||||
|
||||
// Add all our callbacks
|
||||
glfwSetKeyCallback(window, (w, key, scancode, action, mods) -> inputState.onKeyEvent(key, action, mods));
|
||||
glfwSetKeyCallback(window, (w, key, scancode, action, mods) -> inputState.onKeyEvent(w, key, action, mods));
|
||||
glfwSetCharModsCallback(window, (w, codepoint, mods) -> inputState.onCharEvent(codepoint));
|
||||
glfwSetDropCallback(window, (w, count, files) -> inputState.onFileDrop(count, files));
|
||||
glfwSetMouseButtonCallback(window, (w, button, action, mods) -> inputState.onMouseClick(button, action));
|
||||
|
||||
Reference in New Issue
Block a user