zmk icon indicating copy to clipboard operation
zmk copied to clipboard

SYSTEM_POWER and SYSTEM_SLEEP keys don't work

Open exceptioncpp opened this issue 3 years ago • 8 comments

SYSTEM_POWER and SYSTEM_SLEEP keys don't work Example: &kp SYSTEM_SLEEP Expected behavior: put the PC to sleep Actual behavior: nothing happen (USB or BT connection)

It works for the same keyboard but with Pro Micro + QMK and with others keyboards

Windows 11 21H2 22000.376 Sofle V2 + nice!nano v2 Latest ZMK

exceptioncpp avatar Dec 28 '21 20:12 exceptioncpp

Have you tried the C_SLEEP or K_SLEEP codes from this page? I don't even see the code that you're using on that page. Maybe it is one of the deprecated keycodes.

jcmkk3 avatar Dec 28 '21 20:12 jcmkk3

Yes, I tried all *_SLEEP keycodes but only SYSTEM_SLEEP code is equal to other firmwares (including QMK that works).

exceptioncpp avatar Dec 28 '21 20:12 exceptioncpp

This is most likely because we don't process the General Desktop usage page in general (which is what SYSTEM_SLEEP tries to use). See here: https://github.com/zmkfirmware/zmk/blob/main/app/src/hid_listener.c#L19 Currently, we only process keyboard and consumer pages, so SYSTEM_SLEEP won't work until we support the GD page.

Nicell avatar Dec 28 '21 22:12 Nicell

I can confirm that none of the three options listed in the docs (C_SLEEP, K_SLEEP, C_SLEEP_MODE) works under Windows 11. If someone could confirm for Windows 10 as well, it would make sense to state so in the docs (currently all three codes are marked as "? -- not yet tested").

Here's a workaround using the new macro behavior that does work under Windows 11:

   macros {
        // Windows sleep key
        win_sleep: win_sleep {
            wait-ms = <50>;
            tap-ms = <5>;
            compatible = "zmk,behavior-macro";
            label = "WIN_SLEEP_KEY";
            #binding-cells = <0>;
            bindings = <&kp LG(X) &kp U &kp S>;
        };
    };

This defines a &win_sleep behavior that can be added to the keymap. Note that wait-ms must be sufficiently large for the macro to work. Setting it to 50ms works for me. I haven't tweaked it much, though, so one might be able to reduce it. If the macro only opens a menu without putting the computer to sleep, one should chose a larger value for wait-ms.

urob avatar Jun 12 '22 23:06 urob

Windows 11 definitely requires a higher value for wait-ms. I'd recommend around <500>. Using U and S doesn't work either so you'd have to have arrow key inputs.

Since the Kinesis Advantage 360 came out recently, this might be an issue for people using that keyboard and the "programming software" Kinesis provides. For those users, you need to pad the UI changes with &none because they don't provide wait-ms or macro_wait_time.

For a similar functionality to the macro @urob mentions, something like this should work:

bindings = <&kp LG(X)>, <&none>, <&none>, <&none>, <&none>, <&none>, <&kp UP>, <&kp UP>, <&kp RIGHT>, <&none>, <&none>, <&none>, <&kp DOWN>, <&kp ENTER>;

Personally, I'm using a different method:

macro_win_sleep: macro_win_sleep{
    compatible = "zmk,behavior-macro";
    label = "macro_win_sleep";
    #binding-cells = <0>;
    bindings = <&kp LG(D)>, <&none >, <&none >, <&none >, <&none >, <&none >, <&kp LA(F4)>, <&none >, <&none >, <&none >, <&kp UP>, <&kp ENTER>;
};

You can mess around with the number of &nones but the idea is to pad the next binding if there's a UI change.

arshmalhotra avatar Sep 24 '22 09:09 arshmalhotra

Windows 11 definitely requires a higher value for wait-ms. I'd recommend around <500>. Using U and S doesn't work either so you'd have to have arrow key inputs.

On my (brand new) machine, 250ms or fewer is flaky, so you're correct there. However, aside from the timing, @urob's macro works fine for me, including U S.

drjayvee avatar Jan 31 '24 12:01 drjayvee

This is most likely because we don't process the General Desktop usage page in general (which is what SYSTEM_SLEEP tries to use). See here: https://github.com/zmkfirmware/zmk/blob/main/app/src/hid_listener.c#L19 Currently, we only process keyboard and consumer pages, so SYSTEM_SLEEP won't work until we support the GD page.

@Nicell Is there any issue tracking this underlying issue by any chance? Lack of system sleep is a pretty big bummer

jeremyong avatar May 04 '24 20:05 jeremyong

#1535 linked above would be the issue tracking it.

caksoylar avatar May 06 '24 17:05 caksoylar