PowerToys
PowerToys copied to clipboard
Cannot map key to "Sleep".
ℹ Computer information
- Windows build number: 18362.959
- PowerToys version: 0.19.2
- PowerToy module: Keyboard Manager
📝 Provide detailed reproduction steps (if any)
- Click "Remap a key"
- Select Key on left side.
- Select "Sleep" on right side.
✔️ Expected result
Pressing the remapped key puts Windows to sleep.
❌ Actual result
Powertoys says "The following keys are unassigned and you won't be able to use them:", followed by the remapped key name.
📷 Screenshots
This warning just means you loose the original functionality of the "Browser Home" key, i.e. you won't be able to use it like before
Did you try to click "Continue Anyway" and see if it works?
You're right, the error doesn't seem to be the issue. If I map it to "z", for example, it does work despite the warning.
However, it appears that it will not initiate Sleep no matter which key I try to assign.
what keyboard is this? some of the 'special' keys aren't actually real keys so we can't remap.
@arjunbalgovind fyi
It's a Sculpt Ergonomic Keyboard for Business (PN 5KV-00001). It's doesn't have a suspend key on it, which is why I'm trying to remap something else to that function. I'm currently using AutoHotKey to do this, but am exploring whether I could use Powertoys instead.
Same issue here. Mapping a key or shortcut to sleep does not work. I'm on a Logitech ERGO K860.
Ditto. Using MS Natural Ergonomic Keyboard 4000.
The titular issue appears to have been resolved, and the new problem being discussed is also housed in #6020, for reference.
Never mind, we're apparently keeping this issue up.
As I mentioned in the other issue (now closed), I can reproduce this issue as well. I'm on an HP Notebook, which also lacks an actual sleep key. It would be great to see if this works for someone with an actual sleep key on their keyboard.
I can verify that Sleep does not work on my system either, using a Microsoft wireless 6000 keyboard (v3).
Issue #7247
I also have an issue with remapping keys to the sleep command. I'm using a Microsoft Wired Keyboard 600 (Model #: 1366). I first tried to remap the scroll lock to the sleep key. While it did successfully remap, whenever I try hitting the sleep key, the computer wouldn't go to sleep. After reading earlier posts in this issue thread, I thought the problem could be that I couldn't remap the scroll lock key. I then tried the caps lock key (which I know would remap, since I had been remapping it to the shift key). After remapping it, the "sleep" key still wouldn't work. I'm not sure what exactly the problem is. The problem, for me, doesn't seem to be with the key not remapping, rather that the sleep command simply doesn't work when I try issuing it.
For reference, I am using PowerToys version 0.21.1, and my build number is 18363.1082.
Tested this with two different keyboards connected at the same time:
- Old DELL keyboard, mapped "start calculator" key to "Sleep": not working (mapping to e.g. "mute" works)
- Slightly newer DELL keyboard with built-in "Sleep" key: when trying to map another key to "sleep" by pressing "sleep" key in the remappers "Type" mode: computer goes to sleep, remapper ignores keystroke.
Seems the "sleep" keystroke bypasses the keyboard mapper completely. It gets acted upon before the keystroke even reaches the remappers hook and emitting "sleep" from the remapper does nothing because the relevant system hook gets called before remap.
@ALfuhrmann The VK_Sleep is a special key, I would expect it's processed at driver level and no event is passed to any high level application, remapping should not be possible using the current PowerToys architecture.
AutoHotKey can do it just fine, and is what I'm now using instead of the PowerToy.
On 2020/10/29 7:34 am, Enrico Giordani wrote:
The VK_Sleep is a special key, I would expect it's processed at driver level and no event is passed to any high level application, remapping should not be possible using the current PowerToys architecture.
-- You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub [1], or unsubscribe [2].
Links:
[1] https://github.com/microsoft/PowerToys/issues/5291#issuecomment-718793947 [2] https://github.com/notifications/unsubscribe-auth/ALCXEDPZKMFTH2Z24VXR3PDSNF4PZANCNFSM4PLZKG3Q
@ddimick
I forgot to add @ALfuhrmann
since I was replying to someone that is trying to remap the sleep key pressing the sleep key and when they do so, the computer goes to sleep.
Ah, pardon me. I understand your comment now.
@arjunbalgovind any insight here for the sleep key?
I have a feeling we can't remap the Sleep/Power key to something else (I haven't checked if AHK can do that), but for remapping to Sleep I think sending the VK_SLEEP key wouldn't do anything. Instead we would need to do something custom like calling a Win32 API which sets the system to sleep. I found the SetSuspendState API which can do this, but I don't know if it has any constraints such as running as admin or anything like that. VK_SLEEP is probably only processed by the OS or something like that, so using SetSuspendState seems like a better option than figuring out how to get VK_SLEEP to work.
It would be amazing if that API supported warning other system components about an impending sleep, ideally with a reason code of some sort. If that were the case, PowerToys could potentially intercept that signal (if initiated by the sleep key) as a proxy for the actual sleep keystroke, cancel the sleep action, and perform a new keystroke as normally occurs with remapped keys.
@LRitzdorf I don't think it is possible since an application will never receive the information if the sleep event was generated by a key stroke or from Start menu or from any other source.
I tried to put in Win+Esc => Sleep mapping in order to replace software of my own that did the same thing. It doesn't work in PowerToys. Looking back at my source code from 2010 when such things were not uncommon, I was using P/Invoke to call keybd_event on User32.dll, sending a down event, immediately followed by an up event. This worked and still works flawlessly without elevated privileges. Would be great if PowerToys could do this.
I am having the same issue.
If I use qmk firmware keyboard and remap through qmk software it actually can put your pc in sleep. So I think if you own a keyboard that actually have a sleep key it should be working.
I tried this again in 0.55.1 and the remap function itself works fine (I can remap to printscreen for example), but assigning the same key to sleep does not work. Whatever command "sleep" in PT is sending does not seem to be recognised.
I assigned Ctrl + Home to sleep, however it won't recognize it and put the computer to sleep when I hit that shortcut
This issue still seems to be active. Just tried multiple combinations and Sleep does not work. All others work fine.
Remapping the SLEEP key to something else also does not work in PowerToys 0.64.1 I am trying to re-map the top four keys above the number block to F13 to F16. They are SLEEP, VOL UP, VOL DOWN and MUTE. Sleep is the only one that cannot be re-mapped.
According to [PowerToys Keyboard Manager](https://learn.microsoft.com/en-gb/windows/powertoys/keyboard-manager#i-see-keys-listed-in-the-drop-down-menus-that-dont-work-why-is-that)
You can only map a button that is physically available on your keyboard.
So my work around for this issue is
Create a shortcut with shortcut key
using method from: https://www.makeuseof.com/tag/launch-windows-program-keyboard/
to run this command %windir%\System32\rundll32.exe powrprof.dll,SetSuspendState 0,1,0 from https://superuser.com/questions/463646/is-there-a-command-line-tool-to-put-windows-8-to-sleep/463652#463652
and set the shortcut key in Keyboard Manager
I'd be happy to help with this issue.
I wish to deliver the following change in behavior: when the user presses the shortcut remapped to the "Sleep" (VK_SLEEP
) button (as shown in the screenshot), the user's PC goes into the Sleep Mode.
I'm not that proficient with C++ (this is a first time I touched it in the last decade), but after some time tackling with a code base, I found the following possibly far too dirty and hacky solution, but it does work for me (PC goes to sleep when I press CTRL+SHIFT+1):
Inside the KeyboardManagerEngineLibrary, at the HandleShortcutRemapEvent()
method placed in KeyboardEventHandlers.cpp, add the following lines at the end of the else
branch for the if (remapToShortcut)
statement (src):
#include <powrprof.h>
#pragma comment(lib, "Powrprof.lib")
namespace KeyboardEventHandlers
{
// ...
intptr_t HandleShortcutRemapEvent(...
{
for (auto& itShortcut : state.GetSortedShortcutRemapVector(activatedApp))
{
// If the shortcut has been pressed down
if (!it->second.isShortcutInvoked && it->first.CheckModifiersKeyboardState(ii))
{
if (data->lParam->vkCode == it->first.GetActionKey() && (data->wParam == WM_KEYDOWN || data->wParam == WM_SYSKEYDOWN))
{
// ...
if (remapToShortcut)
{
// ...
}
else
{
// ...
// ADDED
if (std::get<DWORD>(it->second.targetShortcut) == VK_SLEEP)
{
BOOL success = SetSuspendState(FALSE, FALSE, FALSE);
if (!success)
{
DWORD error = GetLastError();
if (error == ERROR_PRIVILEGE_NOT_HELD)
{
// process the possible insufficient rights error
}
else
{
// process other possible errors
}
}
else
{
return 1;
}
}
}
}
}
}
}
}
Please note, it will require linking to the Powrprof.lib
. I'm uncertain if this is fine, but I believe it should exist in any supported Windows version.
Another note is I'm not confident how to process the errors properly from the API call in this project and if we need to do that at all.
If anyone who maintains the KeyboardManager module has an idea how to integrate my change properly, please speak out, I'd be happy to follow and create a PR with your guidance.
I see at least one major problem with my "solution": it doesn't reset keys state before going to sleep, so after waking up, the initial hotkey will still be "held".