Skip to content

Commit 23d69f0

Browse files
committed
针对华为设备进行了优化
1 parent 8e3d2b8 commit 23d69f0

10 files changed

Lines changed: 415 additions & 2 deletions

File tree

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
# Moonlight Android
2+
3+
此项目实现对[Moonlight安卓端 威力增强版](https://github.com/qiin2333/moonlight-vplus)的功能改进<br><br>
4+
5+
6+
# 特性
7+
8+
* **修复了开启无障碍服务后无法使用音量键的问题**
9+
10+
* **自动获取无障碍权限**
11+
> *需要通过ADB授权android.permission.WRITE_SECURE_SETTINGS*
12+
13+
* **安卓本地鼠标特殊滚轮的识别**
14+
> *在使用安卓本地鼠标光标时,部分设备无法正确获取滚轮事件,如华为安卓平板,滚动滚动时会产生触屏效果造成大范围滑动*
15+
16+
* **适用于部分平板键盘的按键映射**
17+
> * Home → **Esc**
18+
> * Esc + [1-0, -, =]**F1 - F12**
19+
> * Esc + Q → **呼出串流菜单**
20+
> * 安卓截图键 → **Windows 截图 (Win+Shift+S)**
21+
> * 安卓媒体键 (上一首/播放暂停/下一首) → **F5/F10/F11**
22+
23+
* **支持鼠标中键**
24+
> *部分设备将鼠标中键识别为返回键,此功能开启可以区分触摸返回和鼠标中键造成的返回*
25+
26+
<br><br>
27+
128
<div align="center">
229
<img src="./app/src/main/res/drawable/vplus.webp" width="100" alt="Moonlight V+ Logo">
330

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ android {
147147
// is to please change the applicationId before you publish.
148148
//
149149
// TL;DR: Leave the following line alone!
150-
applicationIdSuffix ".qiin"
150+
// applicationIdSuffix ".qiin"
151+
applicationIdSuffix ".breaded"
151152
resValue "string", "app_label", "Moonlight"
152153
resValue "string", "app_label_root", "Moonlight (Root)"
153154

1.42 KB
Binary file not shown.
1.41 KB
Binary file not shown.

app/src/main/java/com/limelight/Game.java

Lines changed: 289 additions & 0 deletions
Large diffs are not rendered by default.

app/src/main/java/com/limelight/PcView.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.limelight.preferences.GlPreferences;
3333
import com.limelight.preferences.PreferenceConfiguration;
3434
import com.limelight.preferences.StreamSettings;
35+
import com.limelight.services.KeyboardAccessibilityService;
3536
import com.limelight.ui.AdapterFragment;
3637
import com.limelight.ui.AdapterFragmentCallbacks;
3738
import com.limelight.utils.AnalyticsManager;
@@ -195,6 +196,28 @@ public void onServiceDisconnected(ComponentName className) {
195196
protected void onCreate(Bundle savedInstanceState) {
196197
super.onCreate(savedInstanceState);
197198

199+
//自动获取无障碍权限
200+
try {
201+
ComponentName cn = new ComponentName(this, KeyboardAccessibilityService.class);
202+
String myService = cn.flattenToString();
203+
String enabledServices = Settings.Secure.getString(getContentResolver(),
204+
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
205+
206+
if (enabledServices == null || !enabledServices.contains(myService)) {
207+
if (enabledServices == null || enabledServices.isEmpty()) {
208+
enabledServices = myService;
209+
} else {
210+
enabledServices += ":" + myService;
211+
}
212+
213+
// 这里可能会抛异常
214+
Settings.Secure.putString(getContentResolver(),
215+
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, enabledServices);
216+
}
217+
} catch (SecurityException e) {
218+
// 没无障碍权限
219+
}
220+
198221
easyTierController = new EasyTierController(this, this);
199222
inForeground = true;
200223
initBitmapCache();

app/src/main/java/com/limelight/binding/input/KeyboardTranslator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public class KeyboardTranslator implements InputManager.InputDeviceListener {
5555
public static final int VK_SEMICOLON = 59;
5656
public static final int VK_SLASH = 47;
5757
public static final int VK_SPACE = 32;
58-
public static final int VK_PRINTSCREEN = 154;
58+
// public static final int VK_PRINTSCREEN = 154;
59+
public static final int VK_PRINTSCREEN = 44;
5960
public static final int VK_TAB = 9;
6061
public static final int VK_LEFT = 37;
6162
public static final int VK_RIGHT = 39;

app/src/main/java/com/limelight/preferences/PreferenceConfiguration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ public enum PerfOverlayPosition {
233233

234234
private static final boolean DEFAULT_ENABLE_LOCAL_CURSOR_RENDERING = true;
235235
public boolean enableLocalCursorRendering;
236+
//自定义按键映射
237+
public boolean enableCustomKeyMap;
238+
//修复鼠标中键识别
239+
public boolean fixMouseMiddle;
240+
//修复本地鼠标滚轮识别
241+
public boolean fixMouseWheel;
236242
public static final int FRAME_PACING_MIN_LATENCY = 0;
237243
public static final int FRAME_PACING_BALANCED = 1;
238244
public static final int FRAME_PACING_CAP_FPS = 2;
@@ -786,6 +792,9 @@ else if (audioConfig.equals("51")) {
786792
config.enableDoubleClickDrag = prefs.getBoolean(ENABLE_DOUBLE_CLICK_DRAG_PREF_STRING, DEFAULT_ENABLE_DOUBLE_CLICK_DRAG);
787793
config.doubleTapTimeThreshold = prefs.getInt(DOUBLE_TAP_TIME_THRESHOLD_PREF_STRING, DEFAULT_DOUBLE_TAP_TIME_THRESHOLD);
788794
config.enableLocalCursorRendering = prefs.getBoolean(ENABLE_LOCAL_CURSOR_RENDERING_PREF_STRING, DEFAULT_ENABLE_LOCAL_CURSOR_RENDERING);
795+
config.enableCustomKeyMap=prefs.getBoolean("checkbox_special_key_map",false);
796+
config.fixMouseMiddle=prefs.getBoolean("checkbox_mouse_middle",false);
797+
config.fixMouseWheel=prefs.getBoolean("checkbox_mouse_wheel",false);
789798
config.enableSops = prefs.getBoolean(SOPS_PREF_STRING, DEFAULT_SOPS);
790799
config.stretchVideo = prefs.getBoolean(STRETCH_PREF_STRING, DEFAULT_STRETCH);
791800
config.playHostAudio = prefs.getBoolean(HOST_AUDIO_PREF_STRING, DEFAULT_HOST_AUDIO);

app/src/main/java/com/limelight/services/KeyboardAccessibilityService.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22

33
import android.accessibilityservice.AccessibilityService;
44
import android.accessibilityservice.AccessibilityServiceInfo;
5+
import android.text.TextUtils;
56
import android.util.Log;
67
import android.view.KeyEvent;
78
import android.view.accessibility.AccessibilityEvent;
89

10+
import com.limelight.Game;
11+
import com.limelight.preferences.PreferenceConfiguration;
12+
13+
import org.json.JSONArray;
14+
import org.json.JSONObject;
15+
916
/**
1017
* 一个无障碍服务,用于在系统级别拦截硬件键盘事件。
1118
* 主要目的是捕获像 Win 键、Alt+Tab 等被 Android 系统默认行为占用的按键,
@@ -78,6 +85,47 @@ protected void onServiceConnected() {
7885
*/
7986
@Override
8087
protected boolean onKeyEvent(KeyEvent event) {
88+
if (interceptingEnabled && PreferenceConfiguration.readPreferences(this).enableCustomKeyMap) {
89+
int fixedKeyCode = event.getKeyCode();
90+
switch(fixedKeyCode){
91+
case KeyEvent.KEYCODE_HOME:
92+
// HOME键映射ESC
93+
fixedKeyCode = KeyEvent.KEYCODE_ESCAPE;
94+
break;
95+
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
96+
// 安卓上一首键映射Windows F5键
97+
fixedKeyCode = KeyEvent.KEYCODE_F5;
98+
break;
99+
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
100+
// 安卓播放暂停键映射Windows F10键
101+
fixedKeyCode = KeyEvent.KEYCODE_F10;
102+
break;
103+
case KeyEvent.KEYCODE_MEDIA_NEXT:
104+
// 安卓下一首键映射Windows F11键
105+
fixedKeyCode = KeyEvent.KEYCODE_F11;
106+
break;
107+
}
108+
// 安卓截图键映射Windows PRINT SCREEN键
109+
if(fixedKeyCode == KeyEvent.KEYCODE_SYSRQ || fixedKeyCode != event.getKeyCode()) {
110+
if (keyEventCallback != null) {
111+
KeyEvent fixedEvent = new KeyEvent(
112+
event.getDownTime(),
113+
event.getEventTime(),
114+
event.getAction(),
115+
fixedKeyCode,
116+
event.getRepeatCount(),
117+
event.getMetaState(),
118+
event.getDeviceId(),
119+
event.getScanCode(),
120+
event.getFlags(),
121+
event.getSource()
122+
);
123+
keyEventCallback.onKeyEvent(fixedEvent);
124+
}
125+
return true;
126+
}
127+
}
128+
81129
// 小米平板将物理 ESC 键(ScanCode=1)映射为 Android 的 BACK 键(Code=4)。
82130
// 必须在下方的 switch-case 过滤之前进行拦截,否则会被当作普通返回键忽略。
83131
if (event.getScanCode() == 1) {

app/src/main/res/xml/preferences.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,21 @@
269269
android:title="显示一个本地光标"
270270
android:summary="显示一个本地光标,可通过触摸板模式控制光标"
271271
android:defaultValue="false" />
272+
<CheckBoxPreference
273+
android:key="checkbox_special_key_map"
274+
android:title="特殊按键映射"
275+
android:summary="键盘Home键映射Esc键,Esc+数字键/符号映射F1到F12,Esc+Q键映射串流菜单,安卓截图键映射Windows截图,安卓上一首/播放暂停/下一首分别映射到F5/F10/F11。"
276+
android:defaultValue="false" />
277+
<CheckBoxPreference
278+
android:key="checkbox_mouse_middle"
279+
android:title="修复鼠标中键"
280+
android:summary="在一些设备上鼠标中键可能被识别为返回键,选中尝试修复此问题。"
281+
android:defaultValue="true" />
282+
<CheckBoxPreference
283+
android:key="checkbox_mouse_wheel"
284+
android:title="修复本地鼠标滚轮"
285+
android:summary="在一些设备上使用本地鼠标滚轮可能产生触屏滑动事件,选中尝试修复此问题。"
286+
android:defaultValue="true" />
272287
<CheckBoxPreference
273288
android:key="checkbox_sync_touch_event_with_display"
274289
android:title="@string/title_checkbox_sync_touch_event_with_display"

0 commit comments

Comments
 (0)