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.ALPHA, Key.ALPHA, Key.ALPHA }, /* 0,1 */
|
||||
{ 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.SETTINGS, Key.NONE, Key.NONE }, /* 0,5 */
|
||||
{ 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");
|
||||
for (int i = 0; i < buttons.getLength(); i++)
|
||||
if (buttons.item(i).hasAttribute("keycode"))
|
||||
buttons.item(i).addEventListener("click", (final Event evt) -> {
|
||||
if (buttons.item(i).hasAttribute("keycode")) {
|
||||
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();
|
||||
final EventTarget target = evt.getCurrentTarget();
|
||||
final HTMLButtonElement button = target.cast();
|
||||
@ -179,57 +198,40 @@ public class HtmlEngine implements GraphicEngine {
|
||||
final String[] coordinates = code.split(",", 2);
|
||||
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;
|
||||
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)
|
||||
Keyboard.keyRaw(0, 0, false);
|
||||
if (removealpha)
|
||||
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) {
|
||||
if (button.hasAttribute("keycodea")) {
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodea")), false);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodea")), true);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodea")), released);
|
||||
} else {
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), false);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), true);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), released);
|
||||
}
|
||||
} else if (!Keyboard.alpha && Keyboard.shift) {
|
||||
if (button.hasAttribute("keycodes")) {
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), false);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), true);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), released);
|
||||
} else {
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), false);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), true);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), released);
|
||||
}
|
||||
} else if (Keyboard.alpha && Keyboard.shift) {
|
||||
if (button.hasAttribute("keycodesa")) {
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodesa")), false);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodesa")), true);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodesa")), released);
|
||||
} else if (button.hasAttribute("keycodes")) {
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), false);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), true);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycodes")), released);
|
||||
} else {
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), false);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), true);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), released);
|
||||
}
|
||||
} else {
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), false);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), true);
|
||||
Keyboard.debugKey(Integer.parseInt(button.getAttribute("keycode")), released);
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
renderer = new HtmlRenderer(this, g);
|
||||
initialized = true;
|
||||
if (onInitialized != null)
|
||||
onInitialized.run();
|
||||
}
|
||||
|
||||
@JSBody(params = {}, script = "return CSS.supports(\"zoom:2\")")
|
||||
|
Loading…
Reference in New Issue
Block a user