Announcement

Collapse
No announcement yet.

make keyboard sleep button turn off screen or lock?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    make keyboard sleep button turn off screen or lock?

    I have a sleep button on my keyboard that I want to set to turn off the screen, or lock the screen. Since it's on the keyboard it does not show up in settings>power management>energy savings but I should be able to change it by terminal right?

    And how do i change the time until the display is turned off on the lock screen independantly of the timeout when logged in and unlocked? thanks
    Kubuntu 23.04

    #2
    Originally posted by MaruTheAlmighty View Post
    but I should be able to change it by terminal right
    Not necessarily, if it is hardware-bound to the motherboard to send to into sleep.

    But, most likely you can use xmodmap to change things.


    Last edited by claydoh; Jun 24, 2023, 07:58 AM.

    Comment


      #3
      Originally posted by claydoh View Post
      Not necessarily, if it is hardware-bound to the motherboard to send to into sleep.

      But, most likely you can use xmodmap to change things.

      I should've clarified that this is a wireless USB keyboard. I can't see documentation anywhere for how. using scankey it seems the key in question has keycode 142, but i don't know how to verride it triggering sleep

      Comment


        #4
        You would remap the key to run the command that locks the screen (loginctl lock-session)

        Or maybe try the easy way?
        Click image for larger version

Name:	Screenshot_20230624_220320.png
Views:	241
Size:	138.7 KB
ID:	671661

        Comment


          #5
          Thanks for the help, I was able to figure it out eventualy: https://askubuntu.com/questions/1474...-kubuntu-23-04
          update: I found I can disable the button at a lower level with `
          Code:
          xmodmap -e 'keycode 150 = NoSymbol'
          ` but I'm trying to figure out how to make it turn off the screen

          update2: I created the following startup script:

          Code:
          #!/bin/bash
          
          case $1 in
          pre)
          exit 0
          ;;
          post)
          export DISPLAY=:0
          sleep 10
          xmodmap -e 'keycode 150 - XF86Launch5'
          ;;
          esa
          This allowed me to use that key in the shortcuts section of settings

          I had identified the code by running `
          Code:
          xmodmap -pke
          ` which showed `
          Code:
          keycode 150 = XF86Sleep NoSymbol XF86Sleep
          ` and found XF86Launch5 which looked unused and mappable in the shortcuts settings

          Update 2: turning off the display just turns it back on again. I created a custom command `
          Code:
          sh -c "xrandr --output DP-1 --off; loginctl lock-session"
          ` which both turns off my display and locks the screen, and this works perfectly. I found my display by using `
          Code:
          xrandr -q
          ` which revealed it's code to be "DP-1". I set another key to `
          Code:
          xrandr --output DP-1 --auto
          ` which turns the display back on - but only if the screen is not also locked. I'm trying to figure out how to turn the screen on at the login screen, but pressing the power button on the monitor works fine.​
          I do have a new problem: When the screen is locked, custom keyboard shortcuts don't run. Is there a way to run a keyboard shortcut that executes a command at the login screen, or at least when you enter a password (no matter if the password is correct or not)?

          thank you.

          Comment


            #6
            update, I found a much more elegant solution - something I now wish was the first thing I was told.

            in system settings > shortcuts > power management > suspend I turn off the sleep button putting the computer to sleep, and map it to lock session. then I used the notifications setting to set a trigger that when the scree is locked it waits five seconds then turns off the screen.

            Comment


              #7
              Nice solution!

              Going directly to the shortcut (as in my image, for example), if you select a new shortcut that conflicts, you should be prompted of this, and still be allowed to change things to what you want and replacing the original shortcut, so you potentially can save one step.


              Originally posted by MaruTheAlmighty View Post
              I now wish was the first thing I was told.
              It can be hard, as in Linux there are about 65432.1 different ways to do most things.
              Didn't help that I half-assumed it was a laptop hardware button, which adds about 300 extra possibilities.

              Comment


                #8
                Originally posted by claydoh View Post
                Nice solution!


                Didn't help that I half-assumed it was a laptop hardware button, which adds about 300 extra possibilities.
                I could've specified that it was a keyboard button a lot sooner admittedly. Now I still need to figure out pin unlock

                Comment

                Working...
                X