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

[Keyboard Manager] Remapping to App/Mail/Calculator keys does not work #3192

Closed
PhilTb7 opened this issue May 19, 2020 · 9 comments
Closed
Assignees
Labels
Issue-Bug Something isn't working Product-Keyboard Shortcut Manager Issues regarding Keyboard Shortcut Manager Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@PhilTb7
Copy link

PhilTb7 commented May 19, 2020

Environment

Windows build number: Microsoft Windows [Version 10.0.18363.778]
PowerToys version: 0.18
PowerToy module for which you are reporting the bug (if applicable): Keyboard Manager

Steps to reproduce

I have a keyboard with "app buttons" - one for the mail app, one for the calculator.
I flipped this keys with the keyboard manager.

Important note:
my "mail app" key is a key on its own.
my "calculator app" key can only be accessed by also pressing the FN key on my keyboard.

Expected behavior

My "mail app" key should start the calculator
My "calculator app" key should start the mail app

Actual behavior

both keys don't start any app

Screenshots

2020-05-19 20_47_49-PowerToys Settings

@arjunbalgovind
Copy link
Contributor

Hi @tabbed. Do the keys work when you remap them to some other key? For example A->Start App 2 and Start App 2 -> A, and similarly for Start Mail?

@arjunbalgovind arjunbalgovind added the Product-Keyboard Shortcut Manager Issues regarding Keyboard Shortcut Manager label May 19, 2020
@arjunbalgovind
Copy link
Contributor

arjunbalgovind commented May 19, 2020

Tested this out. Looks like remapping any key to Start App 1/2 and Start Mail aren't working.
Repro: Remap A to either of the above.

@arjunbalgovind arjunbalgovind added the Issue-Bug Something isn't working label May 19, 2020
@arjunbalgovind arjunbalgovind changed the title Remapping of keys not working (physical app keys) [Keyboard Manager] Remapping to App/Mail/Calculator keys does not work May 20, 2020
@saahmedm saahmedm added the Priority-0 Bugs that we consider release-blocking/recall-class (P0) label May 29, 2020
@saahmedm saahmedm added this to the v1.0 Release milestone May 29, 2020
@arjunbalgovind
Copy link
Contributor

From what we could find, the reason why it doesn't work is because these keys send a command which requires a higher access level than what Keyboard Manager currently has. Setting a UIAccess flag as per this doc https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-securityoverview could be a workaround which we'll need to verify.

@arjunbalgovind arjunbalgovind self-assigned this Jun 9, 2020
@arjunbalgovind
Copy link
Contributor

The reason for remapping to Calc/Mail not working and for Play/Pause and other media keys (#3255 ) is UAC permissions. By default if the correct UAC settings are turned on, PowerToys does not have permission to inject this to the target application (which is the Shell in this case, since Shell will start Calc/Mail) as they are rejected by the UIPI. Running as admin will also not work since that doesn't give it enough privilege to launch Calculator, Mail, etc. This applies to all keys that send APPCOMMAND messages, including Mail, Calc, Media keys, Browser keys, etc.

According to the docs, the recommended way of giving your application the permissions, is to set the UIAccess flag in the application manifest, which allows the application to bypass UIPI constraints. This flag is generally used by Assistive applications which require this permission in order to perform certain “Windows” tasks which would otherwise not be possible from an application. This doc has a more detailed explanation about it. As an example this is how it would be set in VS.

As an example this is how it would be set in VS.

manifestUiAcess

The UIAccess can’t be used for any application, and there are certain security constraints that need to be followed for it to work:

  • The application must be run from a protected path i.e. a path which requires admin access such as Program Files or System32.
  • The application must be signed
  • The flag must be set in the manifest for the application
    If the flag is set on the application but it is not signed or it is not run from a protected path the following error occurs (more details at this MS blog):

referralReturnedError

This would be the recommended way for us to fix the issue for KBM, however the following problems exist for us:

  • All users may not have installed PowerToys in Program Files
  • Since the app must be signed, this can only be tested with a signed build.
  • KBM currently runs out of the runner PowerToys.exe process, which would mean the UIAccess flag would affect all PowerToys

Based on the above, I think we probably can’t do this for v1, but the following would be needed for us to do this.

  • We would need to move KBM to a separate executable from runner (this would ideally be done when we decouple all modules)
  • We would need to have a second KBM executable which is built with the UIAccess flag set to true.
  • On the settings window, there would be a check box “Allow KBM to bypass UAC restrictions”, and this check box would be hidden unless PT is installed in Program Files. (we would need to add appropriate messages that explain that it needs to be in Program files for that toggle to be available)
    • If the check box is set to true, KBM.exe would not be used and instead it would run KBM-WithUIAccess.exe.

@arjunbalgovind
Copy link
Contributor

@saahmedm @ryanbodrug-microsoft I've mentioned details above about what changes would be required for us to fix this issue and #3255 . Since the changes are PowerToys wide and require alot of work, I think we can't get this for 0.19, we should see whether it would be possible or not for v1 too.

@Megas97
Copy link

Megas97 commented Sep 9, 2020

Is there any info on whether this would be fixed in v1.0 or not? I'm curently using AutoHotkey to create the following remaps:

  1. Pause/Break button to act as a Play/Pause media button
  2. Mail button to open Calculator
  3. My Computer button to put PC to hibernate

№1 works great with PowerToys but the others don't. I'd like to switch from AHK to PowerToys as a game server I play in has blocked AHK and I can't join (even though those 3 things are all I use it for aka I don't cheat...).
Also a question, I saw that PowerToys has a 'Sleep' option for remapping a button. Would that always trigger the sleep function or would it actually trigger hibernate if I've set the sleep button to hibernate my PC in Control Panel's Power Options on Windows?

@crutkas
Copy link
Member

crutkas commented Oct 9, 2020

dup'ing against #3255 as the tracking issue.

@fmcastro
Copy link

fmcastro commented Sep 8, 2022

This seems to have been incorrectly closed or the problem resurfaced? Remmaping the "Mail" key to "StartApp2" should open the calculator on my system but nothing happens:
Windows 11 (22000.856)
PowerToys 0.62.0

@justinbacle
Copy link

I tried remapping "Start App 2" to "Play/Pause Media" whatever I try, I cannot remap the "Start App 2" key to anything.
In the remap key window, when I click OK, I have a warning box stating "Warning: The following keys do not have assignments: Start App 2" even if there is definitely one defined below.
(Running Powertoys v0.77.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Something isn't working Product-Keyboard Shortcut Manager Issues regarding Keyboard Shortcut Manager Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

8 participants