这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion app/src/main/java/com/termux/x11/input/InputEventSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.List;
import java.util.TreeSet;
import java.util.function.Consumer;

/**
* A set of functions to send users' activities, which are represented by Android classes, to
Expand All @@ -39,6 +40,9 @@ public final class InputEventSender {
public boolean pauseKeyInterceptingWithEsc = false;
public boolean stylusIsMouse = false;
public boolean stylusButtonContactModifierMode = false;
public boolean ctrlAltMonitor = false;
public Consumer<Boolean> escapeKeyAction = (down) -> {};
public Consumer<Boolean> ctrlAltKeyAction = (down) -> {};

/** Set of pressed keys for which we've sent TextEvent. */
private final TreeSet<Integer> mPressedTextKeys;
Expand Down Expand Up @@ -215,7 +219,24 @@ else if (e.getUnicodeChar() != 0)
return true;

if (keyCode == KEYCODE_ESCAPE && !pressed && e.hasNoModifiers())
MainActivity.setCapturingEnabled(false);
escapeKeyAction.accept(true);

if (!(e.isAltPressed() && e.isCtrlPressed()) && ctrlAltMonitor) {
ctrlAltMonitor = false;
ctrlAltKeyAction.accept(true);
}
if (e.isAltPressed() && e.isCtrlPressed())
ctrlAltMonitor = true;
if (ctrlAltMonitor)
switch (keyCode) {
case KEYCODE_ALT_LEFT:
case KEYCODE_ALT_RIGHT:
case KEYCODE_CTRL_LEFT:
case KEYCODE_CTRL_RIGHT:
break;
default:
ctrlAltMonitor = false;
}

// We try to send all other key codes to the host directly.
return mInjector.sendKeyEvent(scancode, keyCode, pressed);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/termux/x11/input/TouchInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ public void reloadPreferences(Prefs p) {
volumeUpAction = extractUserActionFromPreferences(p, "volumeUp");
volumeDownAction = extractUserActionFromPreferences(p, "volumeDown");
backButtonAction = extractUserActionFromPreferences(p, "backButton");
mInjector.escapeKeyAction = extractUserActionFromPreferences(p, "escapeKey");
mInjector.ctrlAltKeyAction = extractUserActionFromPreferences(p, "ctrlAltKey");

if(mTouchpadHandler != null)
mTouchpadHandler.reloadPreferences(p);
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

<SwitchPreferenceCompat
android:title="Capture external pointer devices when possible"
android:summary="Intercept all hardware pointer events. Pointer is back to Android after pressing Escape key."
android:summary="Intercept all hardware pointer events. Customize &quot;Response to user actions&quot; to return pointer to Android. "
android:defaultValue="false"
android:key="pointerCapture" />

Expand Down Expand Up @@ -294,5 +294,21 @@
android:defaultValue="toggle soft keyboard"
android:entries="@array/userActionsValues"
android:entryValues="@array/userActionsValues" />

<ListPreference
android:title="Escape"
android:key="escapeKeyAction"
android:summary="%s"
android:defaultValue="release pointer and keyboard capture"
android:entries="@array/userActionsValues"
android:entryValues="@array/userActionsValues" />

<ListPreference
android:title="Ctrl + Alt (availability varies across IMEs and devices)"
android:key="ctrlAltKeyAction"
android:summary="%s"
android:defaultValue="release pointer and keyboard capture"
android:entries="@array/userActionsValues"
android:entryValues="@array/userActionsValues" />
</PreferenceCategory>
</PreferenceScreen>