mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-19 09:39:25 -04:00
Merge pull request #70 from AngelAuraMC/feat/use-controlmap-for-chat
[Feat] Use controlmap for chat
This commit is contained in:
commit
57cb617a15
@ -15,6 +15,7 @@ public class EfficientAndroidLWJGLKeycode {
|
||||
//The value its LWJGL equivalent.
|
||||
private static final int KEYCODE_COUNT = 106;
|
||||
private static final int[] sAndroidKeycodes = new int[KEYCODE_COUNT];
|
||||
private static final int[] sLwjglKeycodesReversed = new int[LwjglGlfwKeycode.GLFW_KEY_LAST];
|
||||
private static final short[] sLwjglKeycodes = new short[KEYCODE_COUNT];
|
||||
private static String[] androidKeyNameArray; /* = new String[androidKeycodes.length]; */
|
||||
private static int mTmpCount = 0;
|
||||
@ -198,6 +199,28 @@ public class EfficientAndroidLWJGLKeycode {
|
||||
sendKeyPress(getValueByIndex(index));
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a GLFW keycode and returns its char primitive. Works with Shift/Caps Lock.
|
||||
* <p>
|
||||
* Non-letter characters return U+0000.
|
||||
*
|
||||
* @param lwjglGlfwKeycode A GLFW key code macro (e.g., {@link LwjglGlfwKeycode#GLFW_KEY_W}).
|
||||
*/
|
||||
public static char getLwjglChar(int lwjglGlfwKeycode){
|
||||
int androidKeycode = sAndroidKeycodes[sLwjglKeycodesReversed[lwjglGlfwKeycode]];
|
||||
KeyEvent key = new KeyEvent(KeyEvent.ACTION_UP, androidKeycode);
|
||||
char charToSend;
|
||||
charToSend = ((char) key.getUnicodeChar());
|
||||
int currentMods = CallbackBridge.getCurrentMods();
|
||||
if (Character.isLetter(charToSend) && (
|
||||
((currentMods & LwjglGlfwKeycode.GLFW_MOD_SHIFT) != 0) ^
|
||||
((currentMods & LwjglGlfwKeycode.GLFW_MOD_CAPS_LOCK) != 0))
|
||||
){
|
||||
charToSend = Character.toUpperCase(charToSend);
|
||||
}
|
||||
return charToSend;
|
||||
}
|
||||
|
||||
public static short getValueByIndex(int index) {
|
||||
return sLwjglKeycodes[index];
|
||||
}
|
||||
@ -218,6 +241,7 @@ public class EfficientAndroidLWJGLKeycode {
|
||||
private static void add(int androidKeycode, short LWJGLKeycode){
|
||||
sAndroidKeycodes[mTmpCount] = androidKeycode;
|
||||
sLwjglKeycodes[mTmpCount] = LWJGLKeycode;
|
||||
sLwjglKeycodesReversed[LWJGLKeycode] = mTmpCount;
|
||||
mTmpCount ++;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.kdt.pojavlaunch.EfficientAndroidLWJGLKeycode;
|
||||
import net.kdt.pojavlaunch.LwjglGlfwKeycode;
|
||||
import net.kdt.pojavlaunch.MainActivity;
|
||||
import net.kdt.pojavlaunch.R;
|
||||
@ -191,7 +192,7 @@ public class ControlButton extends TextView implements ControlInterface {
|
||||
setActivated(isDown);
|
||||
for(int keycode : mProperties.keycodes){
|
||||
if(keycode >= GLFW_KEY_UNKNOWN){
|
||||
sendKeyPress(keycode, CallbackBridge.getCurrentMods(), isDown);
|
||||
sendKeyPress(keycode, EfficientAndroidLWJGLKeycode.getLwjglChar(keycode), CallbackBridge.getCurrentMods(), isDown);
|
||||
CallbackBridge.setModifiers(keycode, isDown);
|
||||
}else{
|
||||
Log.i("punjabilauncher", "sendSpecialKey("+keycode+","+isDown+")");
|
||||
|
@ -56,6 +56,17 @@ public class CallbackBridge {
|
||||
nativeSendCursorPos(mouseX, mouseY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends keycodes if keycode is populated. Used for in-game controls.
|
||||
* Sends character if keychar is populated. Used for chat and text input.
|
||||
* You can refer to glfwSetKeyCallback for the arguments.
|
||||
* @param keycode LwjglGlfwKeycode
|
||||
* @param keychar Literal char. Modifier keys does not affect this.
|
||||
* @param scancode
|
||||
* @param modifiers The action is one of The action is one of GLFW_PRESS, or GLFW_RELEASE.
|
||||
* We don't have GLFW_REPEAT working.
|
||||
* @param isDown If its being pressed down or not. 1 is true.
|
||||
*/
|
||||
public static void sendKeycode(int keycode, char keychar, int scancode, int modifiers, boolean isDown) {
|
||||
// TODO CHECK: This may cause input issue, not receive input!
|
||||
if(keycode != 0) nativeSendKey(keycode,scancode,isDown ? 1 : 0, modifiers);
|
||||
@ -82,6 +93,10 @@ public class CallbackBridge {
|
||||
CallbackBridge.sendKeycode(keyCode, keyChar, scancode, modifiers, status);
|
||||
}
|
||||
|
||||
public static void sendKeyPress(int keyCode, char keyChar, int modifiers, boolean status) {
|
||||
sendKeyPress(keyCode, keyChar, 0, modifiers, status);
|
||||
}
|
||||
|
||||
public static void sendKeyPress(int keyCode) {
|
||||
sendKeyPress(keyCode, CallbackBridge.getCurrentMods(), true);
|
||||
sendKeyPress(keyCode, CallbackBridge.getCurrentMods(), false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user