Compare commits

..

15 Commits

Author SHA1 Message Date
Romain Vimont
dfb7324d7b Mention in README that Ctrl is forwarded 2020-08-01 16:51:38 +02:00
Romain Vimont
d8b3ba170c Update copy-paste section in README
Update documentation regarding the recent copy-paste changes.
2020-08-01 16:51:37 +02:00
Romain Vimont
7ad47dfaab Swap paste shortcuts
For consistency with MOD+c and MOD+x, use MOD+v to inject PASTE.

Use Mod+Shift+v to inject clipboard content as a sequence of text
events.
2020-08-01 16:47:44 +02:00
Romain Vimont
56a115b5c5 Add shortcuts for COPY and CUT
Send COPY and CUT on MOD+c and MOD+x (only supported for Android >= 7).

The shortcuts Ctrl+c and Ctrl+x should generally also work (even before
Android 7), but the active Android app may use them for other actions
instead.
2020-08-01 16:47:43 +02:00
Romain Vimont
8f64a5984b Change "resize to fit" shortcut to MOD+w
For convenience, MOD+x will be used for injecting the CUT keycode.
2020-08-01 16:31:31 +02:00
Romain Vimont
bccd12bf5c Remove "get clipboard" call
Now that every device clipboard change is automatically synchronized to
the computer, the "get clipboard" request (bound to MOD+c) is useless.
2020-08-01 16:31:31 +02:00
Romain Vimont
20d3925099 Set computer clipboard only if necessary
Do not explicitly set the clipboard text if it already contains the
expected content.

Even if copy-paste loops are avoided by the previous commit, this avoids
to trigger a clipboard change on the computer-side.

Refs #1580 <https://github.com/Genymobile/scrcpy/issues/1580>
2020-08-01 16:31:31 +02:00
Romain Vimont
1223a72eb8 Set device clipboard only if necessary
Do not explicitly set the clipboard text if it already contains the
expected content. This avoids possible copy-paste loops between the
computer and the device.
2020-08-01 16:31:31 +02:00
Romain Vimont
7683be8159 Synchronize clipboard on Ctrl+v
Pressing Ctrl+v on the device will typically paste the clipboard
content.

Before sending the key event, synchronize the computer clipboard to the
device clipboard to allow seamless copy-paste.
2020-08-01 16:31:31 +02:00
Romain Vimont
d4ca85d6a8 Forward Shift to the device
This allows to select text using Shift+(arrow keys).

Fixes #942 <https://github.com/Genymobile/scrcpy/issues/942>
2020-08-01 16:31:31 +02:00
Romain Vimont
e6e528f228 Forward Ctrl to the device
Now that the scrcpy shortcut modifier is Alt by default (and can be
configured), forward Ctrl to the device.

This allows to trigger Android shortcuts.

Fixes #555 <https://github.com/Genymobile/scrcpy/issues/555>
2020-08-01 16:31:31 +02:00
Romain Vimont
a5f8b577c5 Ignore text events for shortcuts
Pressing Alt+c generates a text event containing "c", so "c" was sent to
the device when --prefer-text was enabled.

Ignore text events when the mod state matches a shortcut modifier.
2020-08-01 16:31:31 +02:00
Romain Vimont
e4bb7c1d1f Accept Super as shortcut modifier
In addition to (left) Alt, also accept (left) Super. This is especially
convenient for macOS users (Super is the Cmd key).
2020-08-01 16:31:31 +02:00
Romain Vimont
1b76d9fd78 Customize shortcut modifier
Add --shortcut-mod, and use Alt as default modifier.

This paves the way to forward the Ctrl key to the device.
2020-08-01 16:31:27 +02:00
Romain Vimont
63cb93d7d7 Use Ctrl for all shortcuts
Remove the Cmd modifier on macOS, which was possible only for some
shortcuts but not all.

This paves the way to make the shortcut modifier customizable.
2020-08-01 16:31:08 +02:00
6 changed files with 38 additions and 34 deletions

View File

@@ -516,7 +516,7 @@ The actual behavior depends on the active application though. For example,
_Termux_ sends SIGINT on `Ctrl`+`c` instead, and _K-9 Mail_ composes a new
message.
To copy, cut and paste in all cases (but only supported on Android >= 7):
To copy, cut and paste in such cases (but only supported on Android >= 7):
- `MOD`+`c` injects `COPY`
- `MOD`+`x` injects `CUT`
- `MOD`+`v` injects `PASTE` (after computer-to-device clipboard
@@ -526,10 +526,10 @@ In addition, `MOD`+`Shift`+`v` allows to inject the computer clipboard text as a
sequence of key events. This is useful when the component does not accept text
pasting (for example in _Termux_), but it can break non-ASCII content.
*WARNING:* Pasting the computer clipboard to the device (either via `Ctrl`+`v`
or `MOD`+`v`) copies the content in the device clipboard. As a consequence, any
Android application could read its content. You should avoid to paste sensitive
content (like passwords) that way.
**WARNING:** Pasting the computer clipboard to the device (either via `Ctrl`+`v`
or `MOD`+`v`) copies the content into the device clipboard. As a consequence,
any Android application could read its content. You should avoid to paste
sensitive content (like passwords) that way.
#### Text injection preference
@@ -590,19 +590,23 @@ Also see [issue #14].
## Shortcuts
In the following list, `MOD` is the shortcut modifier. By default, it's (left)
`Alt` or (left) `Cmd`.
`Alt` or (left) `Super`.
It can be changed using `--shortcut-mod`. Possible keys are `lctrl`, `rctrl`,
`lalt`, `ralt`, `lcmd` and `rcmd`. For example:
`lalt`, `ralt`, `lsuper` and `rsuper`. For example:
```bash
# use RCtrl for shortcuts
scrcpy --shortcut-mod=rctrl
# use either LCtrl+LAlt or LCmd for shortcuts
scrcpy --shortcut-mod=lctrl+lalt,lcmd
# use either LCtrl+LAlt or LSuper for shortcuts
scrcpy --shortcut-mod=lctrl+lalt,lsuper
```
_[Super] is typically the "Windows" or "Cmd" key._
[Super]: https://en.wikipedia.org/wiki/Super_key_(keyboard_button)
| Action | Shortcut
| ------------------------------------------- |:-----------------------------
| Switch fullscreen mode | `MOD`+`f`
@@ -630,7 +634,7 @@ scrcpy --shortcut-mod=lctrl+lalt,lcmd
| Enable/disable FPS counter (on stdout) | `MOD`+`i`
_¹Double-click on black borders to remove them._
_²Right-click turns the screen on if it was off, presses BACK otherwise._
_²Right-click turns the screen on if it was off, presses BACK otherwise._
_³Only on Android >= 7._
All `Ctrl`+_key_ shortcuts are forwarded to the device, so they are handled by

View File

@@ -151,13 +151,13 @@ The device serial number. Mandatory only if several devices are connected to adb
.TP
.BI "\-\-shortcut\-mod " key[+...]][,...]
Specify the modifiers to use for scrcpy shortcuts. Possible keys are "lctrl", "rctrl", "lalt", "ralt", "lcmd" and "rcmd".
Specify the modifiers to use for scrcpy shortcuts. Possible keys are "lctrl", "rctrl", "lalt", "ralt", "lsuper" and "rsuper".
A shortcut can consist in several keys, separated by '+'. Several shortcuts can be specified, separated by ','.
For example, to use either LCtrl+LAlt or LCmd for scrcpy shortcuts, pass "lctrl+lalt,lcmd".
For example, to use either LCtrl+LAlt or LSuper for scrcpy shortcuts, pass "lctrl+lalt,lsuper".
Default is "lalt,lcmd" (left-Alt or left-Cmd).
Default is "lalt,lsuper" (left-Alt or left-Super).
.TP
.B \-S, \-\-turn\-screen\-off
@@ -218,7 +218,7 @@ Default is 0 (automatic).\n
.SH SHORTCUTS
In the following list, MOD is the shortcut modifier. By default, it's (left)
Alt or (left) Cmd, but it can be configured by \-\-shortcut-mod.
Alt or (left) Super, but it can be configured by \-\-shortcut-mod.
.TP
.B MOD+f

View File

@@ -139,17 +139,17 @@ scrcpy_print_usage(const char *arg0) {
" are connected to adb.\n"
"\n"
" --shortcut-mod key[+...]][,...]\n"
" Specify the modifiers to use for scrcpy shortcuts. Possible\n"
" keys are \"lctrl\", \"rctrl\", \"lalt\", \"ralt\", \"lcmd\"\n"
" and \"rcmd\".\n"
" Specify the modifiers to use for scrcpy shortcuts.\n"
" Possible keys are \"lctrl\", \"rctrl\", \"lalt\", \"ralt\",\n"
" \"lsuper\" and \"rsuper\".\n"
"\n"
" A shortcut can consist in several keys, separated by '+'.\n"
" Several shortcuts can be specified, separated by ','.\n"
"\n"
" For example, to use either LCtrl+LAlt or LCmd for scrcpy\n"
" shortcuts, pass \"lctrl+lalt,lcmd\".\n"
" For example, to use either LCtrl+LAlt or LSuper for scrcpy\n"
" shortcuts, pass \"lctrl+lalt,lsuper\".\n"
"\n"
" Default is \"lalt,lcmd\" (left-Alt or left-Cmd).\n"
" Default is \"lalt,lsuper\" (left-Alt or left-Super).\n"
"\n"
" -S, --turn-screen-off\n"
" Turn the device screen off immediately.\n"
@@ -199,7 +199,7 @@ scrcpy_print_usage(const char *arg0) {
"Shortcuts:\n"
"\n"
" In the following list, MOD is the shortcut modifier. By default,\n"
" it's (left) Alt or (left) Cmd, but it can be configured by\n"
" it's (left) Alt or (left) Super, but it can be configured by\n"
" --shortcut-mod.\n"
"\n"
" MOD+f\n"
@@ -521,10 +521,10 @@ parse_shortcut_mods_item(const char *item, size_t len) {
mod |= SC_MOD_LALT;
} else if (STREQ("ralt", item, key_len)) {
mod |= SC_MOD_RALT;
} else if (STREQ("lcmd", item, key_len)) {
mod |= SC_MOD_LCMD;
} else if (STREQ("rcmd", item, key_len)) {
mod |= SC_MOD_RCMD;
} else if (STREQ("lsuper", item, key_len)) {
mod |= SC_MOD_LSUPER;
} else if (STREQ("rsuper", item, key_len)) {
mod |= SC_MOD_RSUPER;
} else {
LOGW("Unknown modifier key: %.*s", (int) key_len, item);
return 0;
@@ -548,7 +548,7 @@ parse_shortcut_mods(const char *s, struct sc_shortcut_mods *mods) {
unsigned count = 0;
unsigned current = 0;
// LCtrl+LAlt or RCtrl or LCtrl+RCmd: "lctrl+lalt,rctrl,lctrl+rcmd"
// LCtrl+LAlt or RCtrl or LCtrl+RSuper: "lctrl+lalt,rctrl,lctrl+rsuper"
for (;;) {
char *comma = strchr(s, ',');

View File

@@ -28,10 +28,10 @@ to_sdl_mod(unsigned mod) {
if (mod & SC_MOD_RALT) {
sdl_mod |= KMOD_RALT;
}
if (mod & SC_MOD_LCMD) {
if (mod & SC_MOD_LSUPER) {
sdl_mod |= KMOD_LGUI;
}
if (mod & SC_MOD_RCMD) {
if (mod & SC_MOD_RSUPER) {
sdl_mod |= KMOD_RGUI;
}
return sdl_mod;

View File

@@ -27,8 +27,8 @@ enum sc_shortcut_mod {
SC_MOD_RCTRL = 1 << 1,
SC_MOD_LALT = 1 << 2,
SC_MOD_RALT = 1 << 3,
SC_MOD_LCMD = 1 << 4,
SC_MOD_RCMD = 1 << 5,
SC_MOD_LSUPER = 1 << 4,
SC_MOD_RSUPER = 1 << 5,
};
struct sc_shortcut_mods {
@@ -95,7 +95,7 @@ struct scrcpy_options {
.last = DEFAULT_LOCAL_PORT_RANGE_LAST, \
}, \
.shortcut_mods = { \
.data = {SC_MOD_LALT, SC_MOD_LCMD}, \
.data = {SC_MOD_LALT, SC_MOD_LSUPER}, \
.count = 2, \
}, \
.max_size = DEFAULT_MAX_SIZE, \

View File

@@ -143,11 +143,11 @@ static void test_parse_shortcut_mods(void) {
assert(mods.data[0] == SC_MOD_RCTRL);
assert(mods.data[1] == SC_MOD_LALT);
ok = sc_parse_shortcut_mods("lcmd,rcmd+lalt,lctrl+rctrl+ralt", &mods);
ok = sc_parse_shortcut_mods("lsuper,rsuper+lalt,lctrl+rctrl+ralt", &mods);
assert(ok);
assert(mods.count == 3);
assert(mods.data[0] == SC_MOD_LCMD);
assert(mods.data[1] == (SC_MOD_RCMD | SC_MOD_LALT));
assert(mods.data[0] == SC_MOD_LSUPER);
assert(mods.data[1] == (SC_MOD_RSUPER | SC_MOD_LALT));
assert(mods.data[2] == (SC_MOD_LCTRL | SC_MOD_RCTRL | SC_MOD_RALT));
ok = sc_parse_shortcut_mods("", &mods);