Fixed buggy keyboard behavior
This commit is contained in:
parent
f7a7f6d200
commit
6e5ed8ef94
@ -767,7 +767,7 @@ public class Keyboard {
|
|||||||
{ Key.SHIFT, Key.SHIFT, Key.SHIFT }, /* 0,0 */
|
{ Key.SHIFT, Key.SHIFT, Key.SHIFT }, /* 0,0 */
|
||||||
{ Key.ALPHA, Key.ALPHA, Key.ALPHA }, /* 0,1 */
|
{ Key.ALPHA, Key.ALPHA, Key.ALPHA }, /* 0,1 */
|
||||||
{ Key.NONE, Key.NONE, Key.NONE }, /* 0,2 */
|
{ Key.NONE, Key.NONE, Key.NONE }, /* 0,2 */
|
||||||
{ Key.NONE, Key.NONE, Key.NONE }, /* 0,3 */
|
{ Key.UP, Key.NONE, Key.NONE }, /* 0,3 */
|
||||||
{ Key.NONE, Key.NONE, Key.NONE }, /* 0,4 */
|
{ Key.NONE, Key.NONE, Key.NONE }, /* 0,4 */
|
||||||
{ Key.SETTINGS, Key.NONE, Key.NONE }, /* 0,5 */
|
{ Key.SETTINGS, Key.NONE, Key.NONE }, /* 0,5 */
|
||||||
{ Key.BRIGHTNESS_CYCLE, Key.BRIGHTNESS_CYCLE_REVERSE, Key.ZOOM_MODE }, /* 0,6 */
|
{ Key.BRIGHTNESS_CYCLE, Key.BRIGHTNESS_CYCLE_REVERSE, Key.ZOOM_MODE }, /* 0,6 */
|
||||||
|
@ -167,8 +167,27 @@ public class HtmlEngine implements GraphicEngine {
|
|||||||
});
|
});
|
||||||
final NodeList<? extends HTMLElement> buttons = HtmlEngine.document.getBody().getElementsByTagName("button");
|
final NodeList<? extends HTMLElement> buttons = HtmlEngine.document.getBody().getElementsByTagName("button");
|
||||||
for (int i = 0; i < buttons.getLength(); i++)
|
for (int i = 0; i < buttons.getLength(); i++)
|
||||||
if (buttons.item(i).hasAttribute("keycode"))
|
if (buttons.item(i).hasAttribute("keycode")) {
|
||||||
buttons.item(i).addEventListener("click", (final Event evt) -> {
|
buttons.item(i).addEventListener("touchstart", (final Event evt) -> {
|
||||||
|
buttonEvent(evt, false);
|
||||||
|
});
|
||||||
|
buttons.item(i).addEventListener("touchend", (final Event evt) -> {
|
||||||
|
buttonEvent(evt, true);
|
||||||
|
});
|
||||||
|
buttons.item(i).addEventListener("mousedown", (final Event evt) -> {
|
||||||
|
buttonEvent(evt, false);
|
||||||
|
});
|
||||||
|
buttons.item(i).addEventListener("mouseup", (final Event evt) -> {
|
||||||
|
buttonEvent(evt, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
renderer = new HtmlRenderer(this, g);
|
||||||
|
initialized = true;
|
||||||
|
if (onInitialized != null)
|
||||||
|
onInitialized.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonEvent(Event evt, boolean released) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
final EventTarget target = evt.getCurrentTarget();
|
final EventTarget target = evt.getCurrentTarget();
|
||||||
final HTMLButtonElement button = target.cast();
|
final HTMLButtonElement button = target.cast();
|
||||||
@ -179,57 +198,40 @@ public class HtmlEngine implements GraphicEngine {
|
|||||||
final String[] coordinates = code.split(",", 2);
|
final String[] coordinates = code.split(",", 2);
|
||||||
final boolean removeshift = Keyboard.shift && Integer.parseInt(coordinates[0]) != 0 && Integer.parseInt(coordinates[1]) != 0;
|
final boolean removeshift = Keyboard.shift && Integer.parseInt(coordinates[0]) != 0 && Integer.parseInt(coordinates[1]) != 0;
|
||||||
final boolean removealpha = Keyboard.alpha && Integer.parseInt(coordinates[0]) != 0 && Integer.parseInt(coordinates[1]) != 1;
|
final boolean removealpha = Keyboard.alpha && Integer.parseInt(coordinates[0]) != 0 && Integer.parseInt(coordinates[1]) != 1;
|
||||||
Keyboard.keyRaw(Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]), false);
|
Keyboard.keyRaw(Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]), released);
|
||||||
|
if (released) {
|
||||||
if (removeshift)
|
if (removeshift)
|
||||||
Keyboard.keyRaw(0, 0, false);
|
Keyboard.keyRaw(0, 0, false);
|
||||||
if (removealpha)
|
if (removealpha)
|
||||||
Keyboard.keyRaw(0, 1, false);
|
Keyboard.keyRaw(0, 1, false);
|
||||||
Thread.sleep(100);
|
}
|
||||||
Keyboard.keyRaw(Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]), true);
|
|
||||||
if (removeshift)
|
|
||||||
Keyboard.keyRaw(0, 0, true);
|
|
||||||
if (removealpha)
|
|
||||||
Keyboard.keyRaw(0, 1, true);
|
|
||||||
} else if (Keyboard.alpha && !Keyboard.shift) {
|
} else if (Keyboard.alpha && !Keyboard.shift) {
|
||||||
if (button.hasAttribute("keycodea")) {
|
if (button.hasAttribute("keycodea")) {
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodea")), false);
|
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodea")), released);
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodea")), true);
|
|
||||||
} else {
|
} else {
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), false);
|
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), released);
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), true);
|
|
||||||
}
|
}
|
||||||
} else if (!Keyboard.alpha && Keyboard.shift) {
|
} else if (!Keyboard.alpha && Keyboard.shift) {
|
||||||
if (button.hasAttribute("keycodes")) {
|
if (button.hasAttribute("keycodes")) {
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), false);
|
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), released);
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), true);
|
|
||||||
} else {
|
} else {
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), false);
|
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), released);
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), true);
|
|
||||||
}
|
}
|
||||||
} else if (Keyboard.alpha && Keyboard.shift) {
|
} else if (Keyboard.alpha && Keyboard.shift) {
|
||||||
if (button.hasAttribute("keycodesa")) {
|
if (button.hasAttribute("keycodesa")) {
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodesa")), false);
|
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodesa")), released);
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodesa")), true);
|
|
||||||
} else if (button.hasAttribute("keycodes")) {
|
} else if (button.hasAttribute("keycodes")) {
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), false);
|
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), released);
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), true);
|
|
||||||
} else {
|
} else {
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), false);
|
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), released);
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), true);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), false);
|
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), released);
|
||||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), true);
|
|
||||||
}
|
}
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
});
|
|
||||||
renderer = new HtmlRenderer(this, g);
|
|
||||||
initialized = true;
|
|
||||||
if (onInitialized != null)
|
|
||||||
onInitialized.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JSBody(params = {}, script = "return CSS.supports(\"zoom:2\")")
|
@JSBody(params = {}, script = "return CSS.supports(\"zoom:2\")")
|
||||||
|
Loading…
Reference in New Issue
Block a user