diff options
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java')
-rwxr-xr-x | src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java index b40acd02..653cd2d9 100755 --- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java @@ -37,6 +37,8 @@ import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.KeyEvent; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; @Getter public class MTextField extends MPanel { @@ -203,10 +205,25 @@ public class MTextField extends MPanel { } } + private Map<Integer, Long> callKeyHeldIfAfter = new HashMap<>(); @Override - public void keyTyped(char typedChar, int keycode) { + public void keyHeld(char typedChar, int keyCode, long heldMS) { if (!isFocused) return; + Long callAfter = callKeyHeldIfAfter.get(keyCode); + if (callAfter == null) return; + if (callAfter <= System.currentTimeMillis()) this.keyPressed(typedChar, keyCode); + } + + @Override + public void keyReleased(char typedChar, int keyCode, long heldMS) { + callKeyHeldIfAfter.remove(keyCode); + } + @Override + public void keyPressed(char typedChar, int keycode) { + if (!isFocused) return; + if (callKeyHeldIfAfter.containsKey(keycode)) callKeyHeldIfAfter.put(keycode, System.currentTimeMillis()+50); + else callKeyHeldIfAfter.put(keycode, System.currentTimeMillis() + 750); if (selectionStart == -1) { if (keycode == 199) { // home |