How to programme key to turn off display

Forum Forums Official Releases antiX-21/22 “Grup Yorum” How to programme key to turn off display

  • This topic has 8 replies, 4 voices, and was last updated Aug 20-11:58 am by 3guesses.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #87160
    Member
    3guesses

      Hi,

      I often use my laptop unplugged and can currently get almost 10 hours of light use out of it through various means, but to improve this even more I would like to be able to force the screen to blank (it’s currently set at 2 minutes) by pressing one of the function keys. So my questions are:

      – can I force the screen to blank (maybe via acpitool?)
      – can I programme a function key to execute a command?

      Thanks for any help!

      3g

      #87162
      Member
      blur13
        Helpful
        Up
        1
        ::

        Try
        xset dpms force off

        Look at .icewm/keys to link commands to keys.

        #87164
        Member
        PPC
          Helpful
          Up
          1
          ::

          I’ve not paid as much attention to the forum for the last couple of months, but this is a very nice tip to save power specially on laptops, thanks for that blur13!

          @3guesses – I’m not aware of how used you are to Linux, or antiX, but I assume you’re not a complete newbie, since you talked about acpitool. Putting blur’s answer in a more practical way:

          You can run the command:

          xset dpms force off

          to force the screen to be turned off.

          You can test that command on the terminal:

          xset dpms force off &

          The screen will turn on we you press a key (I tested that)

          To add this command to a Function key (or any shortcut keys]:
          antiX menu > Control Centre > Edit [your Window Manager name: IceWM/Fluxbox/JWM]… > “Keys” Tab > Add the above command to a the desired shortcut key(s) and save [you may need to restart your window manager to make sure the changes are enforced].

          Example: if you are using the default IceWM Window Manager, to make F12 turn off your screen, you need to add, to the relevant “keys” file a line like (I have not tested this, I don’t use IceWM, but it should work- if it does not, try adding the & at the end of the command):

          key "F12" xset dpms force off

          Save the “keys” file and try it out (if the key fails to work, try restarting your Window Manager).

          P.

          • This reply was modified 8 months, 3 weeks ago by PPC.
          #87279
          Member
          3guesses
            Helpful
            Up
            0
            ::

            Thanks very much @blur13, @PPC.

            I’ve had a look at ~/.icewm/keys but I have one more problem: I’m not entirely sure what the key combination is!

            Basically on my laptop there is an icon over the F10 key which seems to indicate switch displays (external / internal) which I would like to use (as I don’t have an external display), but I don’t know what the key combination should be in the keys file. This functionality is achieved by pressing Fn+F10 on my laptop, and I assume it would be one of the XF86… multimedia keys, but it seems to be the only one not listed in the standard keys file.

            BTW https://ice-wm.org/man/icewm-keys.html states that you can reload the key assignments by executing:

            icesh keys

            Cheers,

            3g

            EDIT: The key assignment is specified using the #switchkey “Super+p” line! So all sorted – thanks again for your help 😎

            • This reply was modified 8 months, 3 weeks ago by 3guesses.
            #87373
            Member
            blur13
              Helpful
              Up
              0
              ::

              XF86Display is probably what you are looking for, if you want to use key XF86*. I’m not familiar with switchkey but if it works, it works. A useful command for finding what different keys are called is xev.

              #87375
              Member
              blur13
                Helpful
                Up
                1
                ::

                Experimented some more with this. At least on my system the keyrelease event immediately triggers the screen to turn on again, so there needs to be a sleep command before. Icewm keys doesnt handle && so I created a simple script:

                #!/bin/sh
                sleep 1 && xset dpms force off

                Place that in $PATH and use, eg.

                key “Super+F7” turnoffscreen.sh

                This works for me, maybe it will help someone else.

                • This reply was modified 8 months, 2 weeks ago by blur13.
                #87419
                Member
                seriousness
                  Helpful
                  Up
                  1
                  ::

                  In ~/.icewm/keys, I simply map this command to a shortcut:

                  bash -c 'sleep 1; xset dpms force off'

                  #87421
                  Member
                  blur13
                    Helpful
                    Up
                    0
                    ::

                    Thanks! I didn’t know you could do that, much simpler.

                    #87482
                    Member
                    3guesses
                      Helpful
                      Up
                      0
                      ::

                      Experimented some more with this. At least on my system the keyrelease event immediately triggers the screen to turn on again, so there needs to be a sleep command before. Icewm keys doesnt handle && so I created a simple script:

                      #!/bin/sh
                      sleep 1 && xset dpms force off

                      Place that in $PATH and use, eg.

                      key “Super+F7” turnoffscreen.sh

                      This works for me, maybe it will help someone else.

                      I don’t tend to experience that problem using switchkey “Super+p” xset dpms force off in ~/.icewm/keys – very occasionally the screen does blank and then come straight back on again when I press F10, but then I just press F10 again 😎

                      • This reply was modified 8 months, 2 weeks ago by 3guesses.
                    Viewing 9 posts - 1 through 9 (of 9 total)
                    • You must be logged in to reply to this topic.