Skip to content

Commit

Permalink
Initial connection between virtual keyboard and keyDown, keyTyped and…
Browse files Browse the repository at this point in the history
… keyUp events.
  • Loading branch information
lanceewing committed Mar 13, 2024
1 parent 6fc2bd8 commit b827e1e
Showing 1 changed file with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.agifans.agile.ui;

import com.agifans.agile.GameScreen;
import com.agifans.agile.UserInput;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.math.Vector2;

Expand Down Expand Up @@ -134,7 +136,7 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (keyboardType.isInKeyboard(touchXY.x, touchXY.y)) {
Integer keycode = keyboardType.getKeyCode(touchXY.x, touchXY.y);
if (keycode != null) {
keyDown(keycode);
processVirtualKeyboardKeyDown(keycode);
}
if (touchInfo != null) {
touchInfo.lastKey = keycode;
Expand All @@ -143,6 +145,30 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) {

return true;
}

private UserInput getUserInput() {
return gameScreen.getAgileRunner().getUserInput();
}

private void processVirtualKeyboardKeyDown(int keycode) {
if (((keycode >> 8) & 0xFF) == Keys.SHIFT_LEFT) {
getUserInput().keyDown(Keys.SHIFT_LEFT);
}

getUserInput().keyDown(keycode & 0xFF);

if (KeyboardTypeData.KEYTYPED_CHAR_MAP.containsKey(keycode)) {
getUserInput().keyTyped(KeyboardTypeData.KEYTYPED_CHAR_MAP.get(keycode));
}
}

private void processVirtualKeyboardKeyUp(int keycode) {
getUserInput().keyUp(keycode & 0xFF);

if (((keycode >> 8) & 0xFF) == Keys.SHIFT_LEFT) {
getUserInput().keyUp(Keys.SHIFT_LEFT);
}
}

/**
* Updates the AGI Mouse state. AGI Mouse is a fan made hack to the original AGI
Expand Down Expand Up @@ -214,7 +240,7 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) {
if (keyboardType.isInKeyboard(touchXY.x, touchXY.y)) {
Integer keycode = keyboardType.getKeyCode(touchXY.x, touchXY.y);
if (keycode != null) {
keyUp(keycode);
processVirtualKeyboardKeyUp(keycode);
}
} else if (keyboardType.equals(KeyboardType.MOBILE_ON_SCREEN)) {
// If the onscreen keyboard is being shown then if we receive a tap event, it
Expand Down Expand Up @@ -370,13 +396,13 @@ public boolean touchDragged(int screenX, int screenY, int pointer) {
newKey = keyboardType.getKeyCode(touchXY.x, touchXY.y);
}

// If the drag has resulting in the position moving in to or out of a key, then
// we simulate the coresponding key events.
// If the drag has resulted in the position moving in to or out of a key, then
// we simulate the corresponding key events.
if ((lastKey != null) && ((newKey == null) || (newKey != lastKey))) {
keyUp(lastKey);
processVirtualKeyboardKeyUp(lastKey);
}
if ((newKey != null) && ((lastKey == null) || (lastKey != newKey))) {
keyDown(newKey);
processVirtualKeyboardKeyDown(newKey);
}

// Finally we update the new last position and last key for this pointer.
Expand Down

0 comments on commit b827e1e

Please sign in to comment.