Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALT key and Windows key Issue #5318

Open
finaln1 opened this issue Sep 24, 2024 · 10 comments
Open

ALT key and Windows key Issue #5318

finaln1 opened this issue Sep 24, 2024 · 10 comments

Comments

@finaln1
Copy link

finaln1 commented Sep 24, 2024

Hello.

I can't send the ALT key and Windows key of the keyboard connected to the PC to the smartphone while connected to the smartphone via scrcpy in Windows 10.

When I press the ALT key, it responds on the PC. The Windows key also responds on the PC, not the smartphone.

I set --keyboard=uhid, but it's the same problem.

--fullscreen didn't solve the problem either.

Please help.

@rom1v
Copy link
Collaborator

rom1v commented Sep 24, 2024

Alt is captured for scrcpy shortcuts by default (see --shortcut-mod).

If you change the shortcut mode, you can use Alt with UHID keyboard:

scrcpy -K --shortcut-mod=lsuper

But it still not work with SDK keyboard. Probably I should change that now:

diff --git a/app/src/keyboard_sdk.c b/app/src/keyboard_sdk.c
index 00b7f92af..2d9ca85b5 100644
--- a/app/src/keyboard_sdk.c
+++ b/app/src/keyboard_sdk.c
@@ -45,6 +45,10 @@ convert_keycode(enum sc_keycode from, enum android_keycode *to, uint16_t mod,
         {SC_KEYCODE_RCTRL,     AKEYCODE_CTRL_RIGHT},
         {SC_KEYCODE_LSHIFT,    AKEYCODE_SHIFT_LEFT},
         {SC_KEYCODE_RSHIFT,    AKEYCODE_SHIFT_RIGHT},
+        {SC_KEYCODE_LALT,      AKEYCODE_ALT_LEFT},
+        {SC_KEYCODE_RALT,      AKEYCODE_ALT_RIGHT},
+        {SC_KEYCODE_LGUI,      AKEYCODE_META_LEFT},
+        {SC_KEYCODE_RGUI,      AKEYCODE_META_RIGHT},
     };
 
     // Numpad navigation keys.
@@ -166,11 +170,7 @@ convert_keycode(enum sc_keycode from, enum android_keycode *to, uint16_t mod,
         return false;
     }
 
-    if (mod & (SC_MOD_LALT | SC_MOD_RALT | SC_MOD_LGUI | SC_MOD_RGUI)) {
-        return false;
-    }
-
-    // if ALT and META are not pressed, also handle letters and space
+    // Handle letters and space
     entry = SC_INTMAP_FIND_ENTRY(alphaspace_keys, from);
     if (entry) {
         *to = entry->value;

Could you try with this patch?

(if you don't know how to, I can provide a binary)

@rom1v
Copy link
Collaborator

rom1v commented Sep 24, 2024

Try with this binary (replace in the v2.7 release):

  • scrcpy.exe SHA-256: 54673620d62ee888f0e32624f3acf3617fa6a96f25e17dfd45b8ee21654a798

Execute:

scrcpy --shortcut-mod=rctrl

(for example, so that the shortcut mod is the right ctrl key)

Now, you should be able to use Alt and Super.

@finaln1
Copy link
Author

finaln1 commented Sep 25, 2024

Try with this binary (replace in the v2.7 release):

  • scrcpy.exe SHA-256: 54673620d62ee888f0e32624f3acf3617fa6a96f25e17dfd45b8ee21654a798

Execute:

scrcpy --shortcut-mod=rctrl

(for example, so that the shortcut mod is the right ctrl key)

Now, you should be able to use Alt and Super.

Hello, thank you for your kind reply.

Using the new exe file and scrcpy --shortcut-mod=rctrl command you provided, I confirmed that ALT and Super Key are transmitted normally.

But I still have concerns.
I have to use relational mouse mode, and I added --mouse=uhid for this, but with --mouse=uhid, I can't send ALT, Super Key.

I found the cause in the help.

--mouse=mode
Select how to send mouse inputs to the device.
Possible values are "disabled", "sdk", "uhid" and "aoa".
"disabled" does not send mouse inputs to the device.
"sdk" uses the Android system API to deliver mouse eventsto applications.
"uhid" simulates a physical HID mouse using the Linux UHID kernel module on the device.
"aoa" simulates a physical mouse using the AOAv2 protocol. It may only work over USB.
In "uhid" and "aoa" modes, the computer mouse is captured to control the device directly (relative mouse mode).
LAlt, LSuper or RSuper toggle the capture mode, to give control of the mouse back to the computer.
Also see --keyboard and --gamepad.

According to the above, if I use UHID Mouse Mode in scrcpy, it seems to return mouse control to PC when I press Lalt, LSSuper or RSSuper Key.

Sadly, I can't be satisfied with what I want in this situation.
It would have been nice to use the control back to PC as a MOD Key combination, but it's a shame.

@rom1v
Copy link
Collaborator

rom1v commented Sep 25, 2024

Yes, I think the mouse capture key should not be hardcoded to LAlt, LSuper or RSuper. I think it may be the same as the shortcut mod key (so if --shortcut-mods=rctrl, mouse capture/uncapture would be performed by rctrl). What do you think?

@finaln1
Copy link
Author

finaln1 commented Sep 25, 2024

Yes, I think the mouse capture key should not be hardcoded to LAlt, LSuper or RSuper. I think it may be the same as the shortcut mod key (so if --shortcut-mods=rctrl, mouse capture/uncapture would be performed by rctrl). What do you think?

Even if I use --shortcut-mods=rctrl, if I use it with --mouse=uhid, I can't use the ALT key, so I think I need to modify the scrcpy source itself, but I don't know how to do it yet.

@rom1v
Copy link
Collaborator

rom1v commented Sep 25, 2024

Even if I use --shortcut-mods=rctrl, if I use it with --mouse=uhid, I can't use the ALT key

Sure, but would that behavior (using the same key as shortcut mods for the mouse capture key) be ok to you?

@finaln1
Copy link
Author

finaln1 commented Sep 25, 2024

Even if I use --shortcut-mods=rctrl, if I use it with --mouse=uhid, I can't use the ALT key

Sure, but would that behavior (using the same key as shortcut mods for the mouse capture key) be ok to you?

Yes, it would be nice if I could return the control of the mouse to the PC when I used the MOD Key (ex: rctrl) alone or entered it in combination with another key.
(Because rctrl is typically rarely used.)

@rom1v rom1v changed the title PLEASE HELP!! ALT key and Windows key Issue ALT key and Windows key Issue Sep 25, 2024
rom1v added a commit that referenced this issue Sep 27, 2024
Alt and Super (also named Meta) modifier keys are captured for shortcuts
by default (cf --shortcut-mod).

However, when shortcut modifiers are changed, Alt and Super should be
forwarded to the device. This is the case for AOA and UHID keyboards,
but it was not the case for SDK keyboard.

Fixes #5318 <#5318>
rom1v added a commit that referenced this issue Sep 27, 2024
Instead of using separate hardcoded keys for mouse capture/uncapture,
use the shortcut mods.

By changing the shortcut mods (for example --shortcut-mod=rctrl), it
allows to forward Alt and Super to the device.

Fixes #5318 <#5318>
@rom1v
Copy link
Collaborator

rom1v commented Sep 27, 2024

Please test #5322.

@finaln1
Copy link
Author

finaln1 commented Oct 2, 2024

Hello, I'm telling you what I tested.

  1. When I set RCTRL to Mod, when I press RCTRL, mouse control normally goes over to PC.

  2. When I press the Super key, it is transmitted normally to the smartphone, but at the same time, the Super key of the PC is also pressed, and mouse control is transferred to the PC.

  • I find this part uncomfortable. Is it possible to improve it?
  1. When I press the ALT key, it normally passes to my smartphone. But when I press ALT+TAB, ALT+TAB works on my PC.
  • I use my smartphone to remotely control other PCs, so I hope this part can be modified as well.

Thank you for your kindness.

@rom1v
Copy link
Collaborator

rom1v commented Oct 2, 2024

Thank you for your feedback.

  1. When I set RCTRL to Mod, when I press RCTRL, mouse control normally goes over to PC.

👍

  1. When I press the Super key, it is transmitted normally to the smartphone,

👍

but at the same time, the Super key of the PC is also pressed, and mouse control is transferred to the PC.

I cannot reproduce on Linux. I guess the Windows environment captures Super for its own purpose (opening the "start menu" I guess?). It's weird that it both captures and send the event to the application though. Not sure I can do something about it with SDL.

When I press the ALT key, it normally passes to my smartphone.

👍

But when I press ALT+TAB, ALT+TAB works on my PC.

Yes, the Windows environment / window manager captures Alt+tab. There is a SDL hint (SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED), but whatever its value, I can't prevent Alt+tab to be captured by the system.

At least, #5322 fixes forwarding of Alt and Super as expected with SDK keyboard (consistent with UHID/AOA keyboards). After that there are other issues because the system may also capture these keys.

rom1v added a commit that referenced this issue Oct 6, 2024
Alt and Super (also named Meta) modifier keys are captured for shortcuts
by default (cf --shortcut-mod).

However, when shortcut modifiers are changed, Alt and Super should be
forwarded to the device. This is the case for AOA and UHID keyboards,
but it was not the case for SDK keyboard.

Fixes #5318 <#5318>
PR #5322 <#5322>
rom1v added a commit that referenced this issue Oct 6, 2024
Instead of using separate hardcoded keys for mouse capture/uncapture,
use the shortcut mods.

By changing the shortcut mods (for example --shortcut-mod=rctrl), it
allows to forward Alt and Super to the device.

Fixes #5318 <#5318>
PR #5322 <#5322>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants