From f4412eb2323ee5cc70071f8f7a6119673e775f4f Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Sat, 13 Feb 2021 11:20:10 +0700 Subject: [PATCH] New option: treat back button as right mouse Some Android devices treats right mouse input as back button, so enable to convert back to right mouse. --- .../net/kdt/pojavlaunch/AndroidLWJGLKeycode.java | 14 ++++++++++---- .../kdt/pojavlaunch/prefs/LauncherPreferences.java | 2 ++ app_pojavlauncher/src/main/res/values/strings.xml | 2 ++ app_pojavlauncher/src/main/res/xml/pref_main.xml | 5 +++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/AndroidLWJGLKeycode.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/AndroidLWJGLKeycode.java index ff9a12487..ec8134034 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/AndroidLWJGLKeycode.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/AndroidLWJGLKeycode.java @@ -5,6 +5,8 @@ import android.view.*; import java.net.CookieHandler; import java.util.*; + +import net.kdt.pojavlaunch.prefs.LauncherPreferences; import org.lwjgl.glfw.*; public class AndroidLWJGLKeycode { @@ -173,12 +175,16 @@ public class AndroidLWJGLKeycode { try { //System.out.println(((int)keyEvent.getDisplayLabel()) + " " +keyEvent.getDisplayLabel()); - if(keyEvent.getUnicodeChar() != 0) { - char key = (char)keyEvent.getUnicodeChar(); + if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && LauncherPreferences.PREF_BACK_TO_RIGHT_MOUSE) { + BaseMainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, keyEvent.getAction() == KeyEvent.ACTION_DOWN); + } else { + if(keyEvent.getUnicodeChar() != 0) { + char key = (char)keyEvent.getUnicodeChar(); BaseMainActivity.sendKeyPress(androidToLwjglMap.get(keyEvent.getKeyCode()),key,0,CallbackBridge.getCurrentMods(),keyEvent.getAction() == KeyEvent.ACTION_DOWN); - }else{ + }else{ BaseMainActivity.sendKeyPress(androidToLwjglMap.get(keyEvent.getKeyCode()),CallbackBridge.getCurrentMods(),keyEvent.getAction()==KeyEvent.ACTION_DOWN); - } + } + } } catch (Throwable th) { th.printStackTrace(); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java index e1682d0c1..dff619aaa 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java @@ -13,6 +13,7 @@ public class LauncherPreferences public static boolean PREF_FREEFORM = false; public static boolean PREF_HIDE_SIDEBAR = false; public static boolean PREF_IGNORE_NOTCH = false; + public static boolean PREF_BACK_TO_RIGHT_MOUSE = false; public static int PREF_NOTCH_SIZE = 0; public static float PREF_BUTTONSIZE = 100f; public static float PREF_MOUSESCALE = 100f; @@ -28,6 +29,7 @@ public class LauncherPreferences PREF_FREEFORM = DEFAULT_PREF.getBoolean("freeform", false); PREF_HIDE_SIDEBAR = DEFAULT_PREF.getBoolean("hideSidebar", false); PREF_IGNORE_NOTCH = DEFAULT_PREF.getBoolean("ignoreNotch", false); + PREF_BACK_TO_RIGHT_MOUSE = DEFAULT_PREF.getBoolean("backToRightMouse", true); PREF_VERTYPE_RELEASE = DEFAULT_PREF.getBoolean("vertype_release", true); PREF_VERTYPE_SNAPSHOT = DEFAULT_PREF.getBoolean("vertype_snapshot", false); PREF_VERTYPE_OLDALPHA = DEFAULT_PREF.getBoolean("vertype_oldalpha", false); diff --git a/app_pojavlauncher/src/main/res/values/strings.xml b/app_pojavlauncher/src/main/res/values/strings.xml index 7e89b4240..2a44fc521 100644 --- a/app_pojavlauncher/src/main/res/values/strings.xml +++ b/app_pojavlauncher/src/main/res/values/strings.xml @@ -85,6 +85,8 @@ Allows you to decrease the game resolution. 100% is full resolution How long will trigger after long press Change trigger time for long press in destroy block and drop item. + Treat back button as right mouse + Some devices treats external right mouse as back button. If you are using external mouse, you should enable this. Control buttons scaling Upscale them if buttons are too small. Mouse scaling diff --git a/app_pojavlauncher/src/main/res/xml/pref_main.xml b/app_pojavlauncher/src/main/res/xml/pref_main.xml index 2cd769c92..03b10d33d 100644 --- a/app_pojavlauncher/src/main/res/xml/pref_main.xml +++ b/app_pojavlauncher/src/main/res/xml/pref_main.xml @@ -49,6 +49,11 @@ android:key="autoRam" android:summary="@string/auto_ram_subtitle" android:title="@string/auto_ram_title" /> +