forked from moonlight-stream/moonlight-android
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/limelight/KeyboardAccessibilityService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.limelight; | ||
|
||
import android.accessibilityservice.AccessibilityService; | ||
import android.view.KeyEvent; | ||
import android.view.accessibility.AccessibilityEvent; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class KeyboardAccessibilityService extends AccessibilityService { | ||
|
||
private final static List<Integer> BLACKLISTED_KEYS = Arrays.asList(KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_POWER); | ||
|
||
@Override | ||
public boolean onKeyEvent(KeyEvent event) { | ||
int action = event.getAction(); | ||
int keyCode = event.getKeyCode(); | ||
|
||
if (Game.instance != null && Game.instance.isConnected() && !BLACKLISTED_KEYS.contains(keyCode)) { | ||
// Preventing default will disable shortcut actions like alt+tab and etc. | ||
if (action == KeyEvent.ACTION_DOWN) { | ||
Game.instance.handleKeyDown(event); | ||
return true; | ||
} else if (action == KeyEvent.ACTION_UP) { | ||
Game.instance.handleKeyUp(event); | ||
return true; | ||
} | ||
} | ||
|
||
return super.onKeyEvent(event); | ||
} | ||
|
||
@Override | ||
public void onServiceConnected() { | ||
LimeLog.info("Keyboard service is connected"); | ||
} | ||
|
||
@Override | ||
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) { | ||
|
||
} | ||
|
||
@Override | ||
public void onInterrupt() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:accessibilityEventTypes="typeContextClicked|typeViewClicked|typeViewFocused|typeViewScrolled|typeViewSelected|typeWindowContentChanged|typeWindowStateChanged" | ||
android:accessibilityFeedbackType="feedbackSpoken" | ||
android:accessibilityFlags="flagDefault|flagRequestFilterKeyEvents|flagRetrieveInteractiveWindows" | ||
android:canRequestFilterKeyEvents="true" | ||
android:description="@string/accessibility_description_text" | ||
android:notificationTimeout="100" | ||
android:settingsActivity="" | ||
android:summary="@string/keyboard_service_label" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters