How to change mapping for the «PowerOff» key on keyboard?












14















I've bought the ROG G551JM Asus laptop which proven to be Ubuntu-compatible. The computer's keyboard is ill-designed with the key "Poweroff" being an ordinary key, placed in the spot, where one usually finds the "End" key. The computer is fine otherwise, so I bought it with the assumption, that I would be able to somehow "fix" the problem, i.e. remap the PowerOff button into the "End" key.



The PowerOff button made wrong (ASUS G551JM):
ASUS G551JM



Normally there is an «End» key (ASUS N56VZ):
ASUS N56VZ



The "PowerOff" button events are produced by the /dev/input/event2: Power Button device (as reported by evtest) with code 116 (example line from evtest: Event: time 1422895638.246142, type 1 (EV_KEY), code 116 (KEY_POWER), value 1)



The key is also visible to X server, and ultimately Ubuntu can identify key presses as a PowerOff key and launches the "Goodbye user Adam..." semi-transparent dialog box that confirms my will to actually turn the computer off.



The problem is that the binding that binds the PowerOff key press with the routine that displays that confirmation dialog is not visible under dconf-editor and I have no hint where to find it.



Can anyone tell me, where to change (or delete) the default binding for the PowerOff key???



It should be something easy.





edit 21.IX.2016:



There is a way to permanently disable the dialog box, see How do I modify the options for the power button? . I hope that after disabling the power button, it would be possible to re-assign it to something else.










share|improve this question

























  • Have you solved the issue? It would be very useful if you post an answer here.

    – Ezze
    Sep 21 '16 at 13:28








  • 1





    @Ezze Not really (I am using different computer because of this issue). But I managed to permanently disablethe shutdown dialog produced after pressing the key. OK, I'll update the answer.

    – Adam Ryczkowski
    Sep 21 '16 at 16:58











  • Related question on Unix & Linux StackExchange.

    – Ezze
    Sep 22 '16 at 9:29






  • 2





    I hate ASUS so much for removing that key. Home and End are the "meta" keys I use the most... :(

    – Matthieu
    Oct 5 '16 at 11:11
















14















I've bought the ROG G551JM Asus laptop which proven to be Ubuntu-compatible. The computer's keyboard is ill-designed with the key "Poweroff" being an ordinary key, placed in the spot, where one usually finds the "End" key. The computer is fine otherwise, so I bought it with the assumption, that I would be able to somehow "fix" the problem, i.e. remap the PowerOff button into the "End" key.



The PowerOff button made wrong (ASUS G551JM):
ASUS G551JM



Normally there is an «End» key (ASUS N56VZ):
ASUS N56VZ



The "PowerOff" button events are produced by the /dev/input/event2: Power Button device (as reported by evtest) with code 116 (example line from evtest: Event: time 1422895638.246142, type 1 (EV_KEY), code 116 (KEY_POWER), value 1)



The key is also visible to X server, and ultimately Ubuntu can identify key presses as a PowerOff key and launches the "Goodbye user Adam..." semi-transparent dialog box that confirms my will to actually turn the computer off.



The problem is that the binding that binds the PowerOff key press with the routine that displays that confirmation dialog is not visible under dconf-editor and I have no hint where to find it.



Can anyone tell me, where to change (or delete) the default binding for the PowerOff key???



It should be something easy.





edit 21.IX.2016:



There is a way to permanently disable the dialog box, see How do I modify the options for the power button? . I hope that after disabling the power button, it would be possible to re-assign it to something else.










share|improve this question

























  • Have you solved the issue? It would be very useful if you post an answer here.

    – Ezze
    Sep 21 '16 at 13:28








  • 1





    @Ezze Not really (I am using different computer because of this issue). But I managed to permanently disablethe shutdown dialog produced after pressing the key. OK, I'll update the answer.

    – Adam Ryczkowski
    Sep 21 '16 at 16:58











  • Related question on Unix & Linux StackExchange.

    – Ezze
    Sep 22 '16 at 9:29






  • 2





    I hate ASUS so much for removing that key. Home and End are the "meta" keys I use the most... :(

    – Matthieu
    Oct 5 '16 at 11:11














14












14








14


2






I've bought the ROG G551JM Asus laptop which proven to be Ubuntu-compatible. The computer's keyboard is ill-designed with the key "Poweroff" being an ordinary key, placed in the spot, where one usually finds the "End" key. The computer is fine otherwise, so I bought it with the assumption, that I would be able to somehow "fix" the problem, i.e. remap the PowerOff button into the "End" key.



The PowerOff button made wrong (ASUS G551JM):
ASUS G551JM



Normally there is an «End» key (ASUS N56VZ):
ASUS N56VZ



The "PowerOff" button events are produced by the /dev/input/event2: Power Button device (as reported by evtest) with code 116 (example line from evtest: Event: time 1422895638.246142, type 1 (EV_KEY), code 116 (KEY_POWER), value 1)



The key is also visible to X server, and ultimately Ubuntu can identify key presses as a PowerOff key and launches the "Goodbye user Adam..." semi-transparent dialog box that confirms my will to actually turn the computer off.



The problem is that the binding that binds the PowerOff key press with the routine that displays that confirmation dialog is not visible under dconf-editor and I have no hint where to find it.



Can anyone tell me, where to change (or delete) the default binding for the PowerOff key???



It should be something easy.





edit 21.IX.2016:



There is a way to permanently disable the dialog box, see How do I modify the options for the power button? . I hope that after disabling the power button, it would be possible to re-assign it to something else.










share|improve this question
















I've bought the ROG G551JM Asus laptop which proven to be Ubuntu-compatible. The computer's keyboard is ill-designed with the key "Poweroff" being an ordinary key, placed in the spot, where one usually finds the "End" key. The computer is fine otherwise, so I bought it with the assumption, that I would be able to somehow "fix" the problem, i.e. remap the PowerOff button into the "End" key.



The PowerOff button made wrong (ASUS G551JM):
ASUS G551JM



Normally there is an «End» key (ASUS N56VZ):
ASUS N56VZ



The "PowerOff" button events are produced by the /dev/input/event2: Power Button device (as reported by evtest) with code 116 (example line from evtest: Event: time 1422895638.246142, type 1 (EV_KEY), code 116 (KEY_POWER), value 1)



The key is also visible to X server, and ultimately Ubuntu can identify key presses as a PowerOff key and launches the "Goodbye user Adam..." semi-transparent dialog box that confirms my will to actually turn the computer off.



The problem is that the binding that binds the PowerOff key press with the routine that displays that confirmation dialog is not visible under dconf-editor and I have no hint where to find it.



Can anyone tell me, where to change (or delete) the default binding for the PowerOff key???



It should be something easy.





edit 21.IX.2016:



There is a way to permanently disable the dialog box, see How do I modify the options for the power button? . I hope that after disabling the power button, it would be possible to re-assign it to something else.







14.04 unity shortcut-keys






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:24









Community

1




1










asked Feb 2 '15 at 17:14









Adam RyczkowskiAdam Ryczkowski

2,41252253




2,41252253













  • Have you solved the issue? It would be very useful if you post an answer here.

    – Ezze
    Sep 21 '16 at 13:28








  • 1





    @Ezze Not really (I am using different computer because of this issue). But I managed to permanently disablethe shutdown dialog produced after pressing the key. OK, I'll update the answer.

    – Adam Ryczkowski
    Sep 21 '16 at 16:58











  • Related question on Unix & Linux StackExchange.

    – Ezze
    Sep 22 '16 at 9:29






  • 2





    I hate ASUS so much for removing that key. Home and End are the "meta" keys I use the most... :(

    – Matthieu
    Oct 5 '16 at 11:11



















  • Have you solved the issue? It would be very useful if you post an answer here.

    – Ezze
    Sep 21 '16 at 13:28








  • 1





    @Ezze Not really (I am using different computer because of this issue). But I managed to permanently disablethe shutdown dialog produced after pressing the key. OK, I'll update the answer.

    – Adam Ryczkowski
    Sep 21 '16 at 16:58











  • Related question on Unix & Linux StackExchange.

    – Ezze
    Sep 22 '16 at 9:29






  • 2





    I hate ASUS so much for removing that key. Home and End are the "meta" keys I use the most... :(

    – Matthieu
    Oct 5 '16 at 11:11

















Have you solved the issue? It would be very useful if you post an answer here.

– Ezze
Sep 21 '16 at 13:28







Have you solved the issue? It would be very useful if you post an answer here.

– Ezze
Sep 21 '16 at 13:28






1




1





@Ezze Not really (I am using different computer because of this issue). But I managed to permanently disablethe shutdown dialog produced after pressing the key. OK, I'll update the answer.

– Adam Ryczkowski
Sep 21 '16 at 16:58





@Ezze Not really (I am using different computer because of this issue). But I managed to permanently disablethe shutdown dialog produced after pressing the key. OK, I'll update the answer.

– Adam Ryczkowski
Sep 21 '16 at 16:58













Related question on Unix & Linux StackExchange.

– Ezze
Sep 22 '16 at 9:29





Related question on Unix & Linux StackExchange.

– Ezze
Sep 22 '16 at 9:29




2




2





I hate ASUS so much for removing that key. Home and End are the "meta" keys I use the most... :(

– Matthieu
Oct 5 '16 at 11:11





I hate ASUS so much for removing that key. Home and End are the "meta" keys I use the most... :(

– Matthieu
Oct 5 '16 at 11:11










2 Answers
2






active

oldest

votes


















9














I was able to get it working on my ASUS N751JK in Ubuntu 18.04 LTS and Ubuntu 16.04 LTS (tested with Unity desktop environment in both cases and KDE Plasma in 18.04):





  1. First of all, set action of "Power Off" button to nothing.



    Unity



    Like mentioned in answer of Johano Fierra:



    gsettings set org.gnome.settings-daemon.plugins.power button-power "nothing"


    or alternatively sudo apt install dconf-tools and use dconf-editor to change org.gnome.settings-daemon.plugins.power property (like described here). Reboot or logout is required to make it working.



    KDE



    Go to "System Settings", select "Power Management" tab in "Hardware" section and then select "Energy Saving" tab, scroll down, find "When power button pressed" dropdown list and change its value to "Do nothing". Click "Apply" button for changes to take an effect.



    Energy saving




  2. Install xdotool:



    sudo apt install xdotool


    This one will allow us to trigger key events.




  3. Next step is to trigger "End" key press on "Power off" button press.



    Ubuntu 18.04



    Create /etc/acpi/events/power file with the following contents:



    event=button/power
    action=/etc/acpi/power.sh "%e"


    and create /etc/acpi/power.sh script with the following contents:



    #!/bin/sh
    xdotool key End


    and add execution permissions to it:



    sudo chmod +x /etc/acpi/power.sh


    Ubuntu 16.04



    Backup ACPI script used to handle "Power Off" button's event:



    sudo cp /etc/acpi/powerbtn.sh /etc/acpi/powerbtn.sh.backup


    Then edit it, find the following:



    # If logind is running, it already handles power button presses; desktop
    # environments put inhibitors to logind if they want to handle the key
    # themselves.


    and modify the code below so it looks like:



    if pidof systemd-logind >/dev/null; then
    xdotool key End
    exit 0
    fi



  4. In order to apply these changes one should run:



    sudo acpid restart


    Thanks to Adam it's possible to restart acpid automatically when a user logs in (on system boot). So instead of manual sudo acpid restart in terminal each time after reboot add the following line:



    session optional    pam_exec.so /usr/sbin/acpid restart


    to the end of /etc/pam.d/common-session file.








share|improve this answer


























  • What about sudo acpid reload instead of restart? Would that work?

    – Byte Commander
    Sep 25 '16 at 21:16











  • sudo acpid reload also works for me when I run it manually in terminal. But it doesn't help when I place acpid reload in /etc/rc.local or in bash script specified by LightDM's session-setup-script.

    – Ezze
    Sep 26 '16 at 9:09






  • 1





    What solves the acpid restart problem is to add a line session optional pam_exec.so /usr/sbin/acpid restart at the end of /etc/pam.d/common-session. This way the acpid will get restarted just after user login and this is just enough for me. Problem solved at last!!

    – Adam Ryczkowski
    Dec 4 '16 at 20:32






  • 1





    @rtindru, you should gsettings set instead of gsettings get.

    – Ezze
    May 18 '18 at 22:02






  • 1





    In order to make this work in Kubuntu 18.04, I had to give execution permissions to power.sh: sudo chmod +x /etc/acpi/power.sh @Ezze, maybe you could update your answer to include this.

    – LGenzelis
    yesterday





















4














This should do the trick.



Enter in terminal:



gsettings set org.gnome.settings-daemon.plugins.power button-power "nothing"





share|improve this answer





















  • 2





    YES!!! But then there is another thing: how to map it into the «end» key?

    – Adam Ryczkowski
    Feb 2 '15 at 17:31






  • 1





    Entering uncharted territory here, but I think you could just create a xmodmap file config (${HOME}/.xmodmap) and then put this in it: keycode 116 = End, or enter in terminal: xmodmap -e "keycode 116 = End"

    – Johano Fierra
    Feb 2 '15 at 17:53













  • Unfortunately, it doesn't help. It disables capturing of "Power off" button as it seen by xev command and prevents xmodmap to remap it. And by the way, "Power off" button's keycode may be different (124 for my ASUS N751JK).

    – Ezze
    Sep 21 '16 at 13:26











  • It should not disable the ability to capture the button... but how about this. Enter in terminal: gsettings set org.gnome.settings-daemon.plugins.power button-power "shutdown" (so pressing the button is captured), then edit /etc/acpi/events/powerbtn and comment out the line #action=/etc/acpi/powerbtn.sh, and then enter in terminal: xmodmap -e "keycode 124 = End" This should prevent the power button from doing anything and in the same time map it to the End key.

    – Johano Fierra
    Sep 22 '16 at 17:15






  • 1





    It doesn't help too cause "Power off" event is handled not only by powerbtn.sh script but also by (at least) systemd-logind service (probably, it uses button-power setting you mentioned in your answer). You can find if pidof systemd-logind >/dev/null; then...exit 0 line in powerbtn.sh which means that the script lets systemd-logind to handle "Power off" event by itself when desktop session is active. One thing you are right about — changing button-power value doesn't affect the ability to capture the key but it's already captured by some process (systemd-logind or other).

    – Ezze
    Sep 26 '16 at 8:53













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f580902%2fhow-to-change-mapping-for-the-poweroff-key-on-keyboard%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









9














I was able to get it working on my ASUS N751JK in Ubuntu 18.04 LTS and Ubuntu 16.04 LTS (tested with Unity desktop environment in both cases and KDE Plasma in 18.04):





  1. First of all, set action of "Power Off" button to nothing.



    Unity



    Like mentioned in answer of Johano Fierra:



    gsettings set org.gnome.settings-daemon.plugins.power button-power "nothing"


    or alternatively sudo apt install dconf-tools and use dconf-editor to change org.gnome.settings-daemon.plugins.power property (like described here). Reboot or logout is required to make it working.



    KDE



    Go to "System Settings", select "Power Management" tab in "Hardware" section and then select "Energy Saving" tab, scroll down, find "When power button pressed" dropdown list and change its value to "Do nothing". Click "Apply" button for changes to take an effect.



    Energy saving




  2. Install xdotool:



    sudo apt install xdotool


    This one will allow us to trigger key events.




  3. Next step is to trigger "End" key press on "Power off" button press.



    Ubuntu 18.04



    Create /etc/acpi/events/power file with the following contents:



    event=button/power
    action=/etc/acpi/power.sh "%e"


    and create /etc/acpi/power.sh script with the following contents:



    #!/bin/sh
    xdotool key End


    and add execution permissions to it:



    sudo chmod +x /etc/acpi/power.sh


    Ubuntu 16.04



    Backup ACPI script used to handle "Power Off" button's event:



    sudo cp /etc/acpi/powerbtn.sh /etc/acpi/powerbtn.sh.backup


    Then edit it, find the following:



    # If logind is running, it already handles power button presses; desktop
    # environments put inhibitors to logind if they want to handle the key
    # themselves.


    and modify the code below so it looks like:



    if pidof systemd-logind >/dev/null; then
    xdotool key End
    exit 0
    fi



  4. In order to apply these changes one should run:



    sudo acpid restart


    Thanks to Adam it's possible to restart acpid automatically when a user logs in (on system boot). So instead of manual sudo acpid restart in terminal each time after reboot add the following line:



    session optional    pam_exec.so /usr/sbin/acpid restart


    to the end of /etc/pam.d/common-session file.








share|improve this answer


























  • What about sudo acpid reload instead of restart? Would that work?

    – Byte Commander
    Sep 25 '16 at 21:16











  • sudo acpid reload also works for me when I run it manually in terminal. But it doesn't help when I place acpid reload in /etc/rc.local or in bash script specified by LightDM's session-setup-script.

    – Ezze
    Sep 26 '16 at 9:09






  • 1





    What solves the acpid restart problem is to add a line session optional pam_exec.so /usr/sbin/acpid restart at the end of /etc/pam.d/common-session. This way the acpid will get restarted just after user login and this is just enough for me. Problem solved at last!!

    – Adam Ryczkowski
    Dec 4 '16 at 20:32






  • 1





    @rtindru, you should gsettings set instead of gsettings get.

    – Ezze
    May 18 '18 at 22:02






  • 1





    In order to make this work in Kubuntu 18.04, I had to give execution permissions to power.sh: sudo chmod +x /etc/acpi/power.sh @Ezze, maybe you could update your answer to include this.

    – LGenzelis
    yesterday


















9














I was able to get it working on my ASUS N751JK in Ubuntu 18.04 LTS and Ubuntu 16.04 LTS (tested with Unity desktop environment in both cases and KDE Plasma in 18.04):





  1. First of all, set action of "Power Off" button to nothing.



    Unity



    Like mentioned in answer of Johano Fierra:



    gsettings set org.gnome.settings-daemon.plugins.power button-power "nothing"


    or alternatively sudo apt install dconf-tools and use dconf-editor to change org.gnome.settings-daemon.plugins.power property (like described here). Reboot or logout is required to make it working.



    KDE



    Go to "System Settings", select "Power Management" tab in "Hardware" section and then select "Energy Saving" tab, scroll down, find "When power button pressed" dropdown list and change its value to "Do nothing". Click "Apply" button for changes to take an effect.



    Energy saving




  2. Install xdotool:



    sudo apt install xdotool


    This one will allow us to trigger key events.




  3. Next step is to trigger "End" key press on "Power off" button press.



    Ubuntu 18.04



    Create /etc/acpi/events/power file with the following contents:



    event=button/power
    action=/etc/acpi/power.sh "%e"


    and create /etc/acpi/power.sh script with the following contents:



    #!/bin/sh
    xdotool key End


    and add execution permissions to it:



    sudo chmod +x /etc/acpi/power.sh


    Ubuntu 16.04



    Backup ACPI script used to handle "Power Off" button's event:



    sudo cp /etc/acpi/powerbtn.sh /etc/acpi/powerbtn.sh.backup


    Then edit it, find the following:



    # If logind is running, it already handles power button presses; desktop
    # environments put inhibitors to logind if they want to handle the key
    # themselves.


    and modify the code below so it looks like:



    if pidof systemd-logind >/dev/null; then
    xdotool key End
    exit 0
    fi



  4. In order to apply these changes one should run:



    sudo acpid restart


    Thanks to Adam it's possible to restart acpid automatically when a user logs in (on system boot). So instead of manual sudo acpid restart in terminal each time after reboot add the following line:



    session optional    pam_exec.so /usr/sbin/acpid restart


    to the end of /etc/pam.d/common-session file.








share|improve this answer


























  • What about sudo acpid reload instead of restart? Would that work?

    – Byte Commander
    Sep 25 '16 at 21:16











  • sudo acpid reload also works for me when I run it manually in terminal. But it doesn't help when I place acpid reload in /etc/rc.local or in bash script specified by LightDM's session-setup-script.

    – Ezze
    Sep 26 '16 at 9:09






  • 1





    What solves the acpid restart problem is to add a line session optional pam_exec.so /usr/sbin/acpid restart at the end of /etc/pam.d/common-session. This way the acpid will get restarted just after user login and this is just enough for me. Problem solved at last!!

    – Adam Ryczkowski
    Dec 4 '16 at 20:32






  • 1





    @rtindru, you should gsettings set instead of gsettings get.

    – Ezze
    May 18 '18 at 22:02






  • 1





    In order to make this work in Kubuntu 18.04, I had to give execution permissions to power.sh: sudo chmod +x /etc/acpi/power.sh @Ezze, maybe you could update your answer to include this.

    – LGenzelis
    yesterday
















9












9








9







I was able to get it working on my ASUS N751JK in Ubuntu 18.04 LTS and Ubuntu 16.04 LTS (tested with Unity desktop environment in both cases and KDE Plasma in 18.04):





  1. First of all, set action of "Power Off" button to nothing.



    Unity



    Like mentioned in answer of Johano Fierra:



    gsettings set org.gnome.settings-daemon.plugins.power button-power "nothing"


    or alternatively sudo apt install dconf-tools and use dconf-editor to change org.gnome.settings-daemon.plugins.power property (like described here). Reboot or logout is required to make it working.



    KDE



    Go to "System Settings", select "Power Management" tab in "Hardware" section and then select "Energy Saving" tab, scroll down, find "When power button pressed" dropdown list and change its value to "Do nothing". Click "Apply" button for changes to take an effect.



    Energy saving




  2. Install xdotool:



    sudo apt install xdotool


    This one will allow us to trigger key events.




  3. Next step is to trigger "End" key press on "Power off" button press.



    Ubuntu 18.04



    Create /etc/acpi/events/power file with the following contents:



    event=button/power
    action=/etc/acpi/power.sh "%e"


    and create /etc/acpi/power.sh script with the following contents:



    #!/bin/sh
    xdotool key End


    and add execution permissions to it:



    sudo chmod +x /etc/acpi/power.sh


    Ubuntu 16.04



    Backup ACPI script used to handle "Power Off" button's event:



    sudo cp /etc/acpi/powerbtn.sh /etc/acpi/powerbtn.sh.backup


    Then edit it, find the following:



    # If logind is running, it already handles power button presses; desktop
    # environments put inhibitors to logind if they want to handle the key
    # themselves.


    and modify the code below so it looks like:



    if pidof systemd-logind >/dev/null; then
    xdotool key End
    exit 0
    fi



  4. In order to apply these changes one should run:



    sudo acpid restart


    Thanks to Adam it's possible to restart acpid automatically when a user logs in (on system boot). So instead of manual sudo acpid restart in terminal each time after reboot add the following line:



    session optional    pam_exec.so /usr/sbin/acpid restart


    to the end of /etc/pam.d/common-session file.








share|improve this answer















I was able to get it working on my ASUS N751JK in Ubuntu 18.04 LTS and Ubuntu 16.04 LTS (tested with Unity desktop environment in both cases and KDE Plasma in 18.04):





  1. First of all, set action of "Power Off" button to nothing.



    Unity



    Like mentioned in answer of Johano Fierra:



    gsettings set org.gnome.settings-daemon.plugins.power button-power "nothing"


    or alternatively sudo apt install dconf-tools and use dconf-editor to change org.gnome.settings-daemon.plugins.power property (like described here). Reboot or logout is required to make it working.



    KDE



    Go to "System Settings", select "Power Management" tab in "Hardware" section and then select "Energy Saving" tab, scroll down, find "When power button pressed" dropdown list and change its value to "Do nothing". Click "Apply" button for changes to take an effect.



    Energy saving




  2. Install xdotool:



    sudo apt install xdotool


    This one will allow us to trigger key events.




  3. Next step is to trigger "End" key press on "Power off" button press.



    Ubuntu 18.04



    Create /etc/acpi/events/power file with the following contents:



    event=button/power
    action=/etc/acpi/power.sh "%e"


    and create /etc/acpi/power.sh script with the following contents:



    #!/bin/sh
    xdotool key End


    and add execution permissions to it:



    sudo chmod +x /etc/acpi/power.sh


    Ubuntu 16.04



    Backup ACPI script used to handle "Power Off" button's event:



    sudo cp /etc/acpi/powerbtn.sh /etc/acpi/powerbtn.sh.backup


    Then edit it, find the following:



    # If logind is running, it already handles power button presses; desktop
    # environments put inhibitors to logind if they want to handle the key
    # themselves.


    and modify the code below so it looks like:



    if pidof systemd-logind >/dev/null; then
    xdotool key End
    exit 0
    fi



  4. In order to apply these changes one should run:



    sudo acpid restart


    Thanks to Adam it's possible to restart acpid automatically when a user logs in (on system boot). So instead of manual sudo acpid restart in terminal each time after reboot add the following line:



    session optional    pam_exec.so /usr/sbin/acpid restart


    to the end of /etc/pam.d/common-session file.









share|improve this answer














share|improve this answer



share|improve this answer








edited 7 hours ago

























answered Sep 22 '16 at 0:15









EzzeEzze

3051515




3051515













  • What about sudo acpid reload instead of restart? Would that work?

    – Byte Commander
    Sep 25 '16 at 21:16











  • sudo acpid reload also works for me when I run it manually in terminal. But it doesn't help when I place acpid reload in /etc/rc.local or in bash script specified by LightDM's session-setup-script.

    – Ezze
    Sep 26 '16 at 9:09






  • 1





    What solves the acpid restart problem is to add a line session optional pam_exec.so /usr/sbin/acpid restart at the end of /etc/pam.d/common-session. This way the acpid will get restarted just after user login and this is just enough for me. Problem solved at last!!

    – Adam Ryczkowski
    Dec 4 '16 at 20:32






  • 1





    @rtindru, you should gsettings set instead of gsettings get.

    – Ezze
    May 18 '18 at 22:02






  • 1





    In order to make this work in Kubuntu 18.04, I had to give execution permissions to power.sh: sudo chmod +x /etc/acpi/power.sh @Ezze, maybe you could update your answer to include this.

    – LGenzelis
    yesterday





















  • What about sudo acpid reload instead of restart? Would that work?

    – Byte Commander
    Sep 25 '16 at 21:16











  • sudo acpid reload also works for me when I run it manually in terminal. But it doesn't help when I place acpid reload in /etc/rc.local or in bash script specified by LightDM's session-setup-script.

    – Ezze
    Sep 26 '16 at 9:09






  • 1





    What solves the acpid restart problem is to add a line session optional pam_exec.so /usr/sbin/acpid restart at the end of /etc/pam.d/common-session. This way the acpid will get restarted just after user login and this is just enough for me. Problem solved at last!!

    – Adam Ryczkowski
    Dec 4 '16 at 20:32






  • 1





    @rtindru, you should gsettings set instead of gsettings get.

    – Ezze
    May 18 '18 at 22:02






  • 1





    In order to make this work in Kubuntu 18.04, I had to give execution permissions to power.sh: sudo chmod +x /etc/acpi/power.sh @Ezze, maybe you could update your answer to include this.

    – LGenzelis
    yesterday



















What about sudo acpid reload instead of restart? Would that work?

– Byte Commander
Sep 25 '16 at 21:16





What about sudo acpid reload instead of restart? Would that work?

– Byte Commander
Sep 25 '16 at 21:16













sudo acpid reload also works for me when I run it manually in terminal. But it doesn't help when I place acpid reload in /etc/rc.local or in bash script specified by LightDM's session-setup-script.

– Ezze
Sep 26 '16 at 9:09





sudo acpid reload also works for me when I run it manually in terminal. But it doesn't help when I place acpid reload in /etc/rc.local or in bash script specified by LightDM's session-setup-script.

– Ezze
Sep 26 '16 at 9:09




1




1





What solves the acpid restart problem is to add a line session optional pam_exec.so /usr/sbin/acpid restart at the end of /etc/pam.d/common-session. This way the acpid will get restarted just after user login and this is just enough for me. Problem solved at last!!

– Adam Ryczkowski
Dec 4 '16 at 20:32





What solves the acpid restart problem is to add a line session optional pam_exec.so /usr/sbin/acpid restart at the end of /etc/pam.d/common-session. This way the acpid will get restarted just after user login and this is just enough for me. Problem solved at last!!

– Adam Ryczkowski
Dec 4 '16 at 20:32




1




1





@rtindru, you should gsettings set instead of gsettings get.

– Ezze
May 18 '18 at 22:02





@rtindru, you should gsettings set instead of gsettings get.

– Ezze
May 18 '18 at 22:02




1




1





In order to make this work in Kubuntu 18.04, I had to give execution permissions to power.sh: sudo chmod +x /etc/acpi/power.sh @Ezze, maybe you could update your answer to include this.

– LGenzelis
yesterday







In order to make this work in Kubuntu 18.04, I had to give execution permissions to power.sh: sudo chmod +x /etc/acpi/power.sh @Ezze, maybe you could update your answer to include this.

– LGenzelis
yesterday















4














This should do the trick.



Enter in terminal:



gsettings set org.gnome.settings-daemon.plugins.power button-power "nothing"





share|improve this answer





















  • 2





    YES!!! But then there is another thing: how to map it into the «end» key?

    – Adam Ryczkowski
    Feb 2 '15 at 17:31






  • 1





    Entering uncharted territory here, but I think you could just create a xmodmap file config (${HOME}/.xmodmap) and then put this in it: keycode 116 = End, or enter in terminal: xmodmap -e "keycode 116 = End"

    – Johano Fierra
    Feb 2 '15 at 17:53













  • Unfortunately, it doesn't help. It disables capturing of "Power off" button as it seen by xev command and prevents xmodmap to remap it. And by the way, "Power off" button's keycode may be different (124 for my ASUS N751JK).

    – Ezze
    Sep 21 '16 at 13:26











  • It should not disable the ability to capture the button... but how about this. Enter in terminal: gsettings set org.gnome.settings-daemon.plugins.power button-power "shutdown" (so pressing the button is captured), then edit /etc/acpi/events/powerbtn and comment out the line #action=/etc/acpi/powerbtn.sh, and then enter in terminal: xmodmap -e "keycode 124 = End" This should prevent the power button from doing anything and in the same time map it to the End key.

    – Johano Fierra
    Sep 22 '16 at 17:15






  • 1





    It doesn't help too cause "Power off" event is handled not only by powerbtn.sh script but also by (at least) systemd-logind service (probably, it uses button-power setting you mentioned in your answer). You can find if pidof systemd-logind >/dev/null; then...exit 0 line in powerbtn.sh which means that the script lets systemd-logind to handle "Power off" event by itself when desktop session is active. One thing you are right about — changing button-power value doesn't affect the ability to capture the key but it's already captured by some process (systemd-logind or other).

    – Ezze
    Sep 26 '16 at 8:53


















4














This should do the trick.



Enter in terminal:



gsettings set org.gnome.settings-daemon.plugins.power button-power "nothing"





share|improve this answer





















  • 2





    YES!!! But then there is another thing: how to map it into the «end» key?

    – Adam Ryczkowski
    Feb 2 '15 at 17:31






  • 1





    Entering uncharted territory here, but I think you could just create a xmodmap file config (${HOME}/.xmodmap) and then put this in it: keycode 116 = End, or enter in terminal: xmodmap -e "keycode 116 = End"

    – Johano Fierra
    Feb 2 '15 at 17:53













  • Unfortunately, it doesn't help. It disables capturing of "Power off" button as it seen by xev command and prevents xmodmap to remap it. And by the way, "Power off" button's keycode may be different (124 for my ASUS N751JK).

    – Ezze
    Sep 21 '16 at 13:26











  • It should not disable the ability to capture the button... but how about this. Enter in terminal: gsettings set org.gnome.settings-daemon.plugins.power button-power "shutdown" (so pressing the button is captured), then edit /etc/acpi/events/powerbtn and comment out the line #action=/etc/acpi/powerbtn.sh, and then enter in terminal: xmodmap -e "keycode 124 = End" This should prevent the power button from doing anything and in the same time map it to the End key.

    – Johano Fierra
    Sep 22 '16 at 17:15






  • 1





    It doesn't help too cause "Power off" event is handled not only by powerbtn.sh script but also by (at least) systemd-logind service (probably, it uses button-power setting you mentioned in your answer). You can find if pidof systemd-logind >/dev/null; then...exit 0 line in powerbtn.sh which means that the script lets systemd-logind to handle "Power off" event by itself when desktop session is active. One thing you are right about — changing button-power value doesn't affect the ability to capture the key but it's already captured by some process (systemd-logind or other).

    – Ezze
    Sep 26 '16 at 8:53
















4












4








4







This should do the trick.



Enter in terminal:



gsettings set org.gnome.settings-daemon.plugins.power button-power "nothing"





share|improve this answer















This should do the trick.



Enter in terminal:



gsettings set org.gnome.settings-daemon.plugins.power button-power "nothing"






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 2 '15 at 17:22

























answered Feb 2 '15 at 17:17









Johano FierraJohano Fierra

1615




1615








  • 2





    YES!!! But then there is another thing: how to map it into the «end» key?

    – Adam Ryczkowski
    Feb 2 '15 at 17:31






  • 1





    Entering uncharted territory here, but I think you could just create a xmodmap file config (${HOME}/.xmodmap) and then put this in it: keycode 116 = End, or enter in terminal: xmodmap -e "keycode 116 = End"

    – Johano Fierra
    Feb 2 '15 at 17:53













  • Unfortunately, it doesn't help. It disables capturing of "Power off" button as it seen by xev command and prevents xmodmap to remap it. And by the way, "Power off" button's keycode may be different (124 for my ASUS N751JK).

    – Ezze
    Sep 21 '16 at 13:26











  • It should not disable the ability to capture the button... but how about this. Enter in terminal: gsettings set org.gnome.settings-daemon.plugins.power button-power "shutdown" (so pressing the button is captured), then edit /etc/acpi/events/powerbtn and comment out the line #action=/etc/acpi/powerbtn.sh, and then enter in terminal: xmodmap -e "keycode 124 = End" This should prevent the power button from doing anything and in the same time map it to the End key.

    – Johano Fierra
    Sep 22 '16 at 17:15






  • 1





    It doesn't help too cause "Power off" event is handled not only by powerbtn.sh script but also by (at least) systemd-logind service (probably, it uses button-power setting you mentioned in your answer). You can find if pidof systemd-logind >/dev/null; then...exit 0 line in powerbtn.sh which means that the script lets systemd-logind to handle "Power off" event by itself when desktop session is active. One thing you are right about — changing button-power value doesn't affect the ability to capture the key but it's already captured by some process (systemd-logind or other).

    – Ezze
    Sep 26 '16 at 8:53
















  • 2





    YES!!! But then there is another thing: how to map it into the «end» key?

    – Adam Ryczkowski
    Feb 2 '15 at 17:31






  • 1





    Entering uncharted territory here, but I think you could just create a xmodmap file config (${HOME}/.xmodmap) and then put this in it: keycode 116 = End, or enter in terminal: xmodmap -e "keycode 116 = End"

    – Johano Fierra
    Feb 2 '15 at 17:53













  • Unfortunately, it doesn't help. It disables capturing of "Power off" button as it seen by xev command and prevents xmodmap to remap it. And by the way, "Power off" button's keycode may be different (124 for my ASUS N751JK).

    – Ezze
    Sep 21 '16 at 13:26











  • It should not disable the ability to capture the button... but how about this. Enter in terminal: gsettings set org.gnome.settings-daemon.plugins.power button-power "shutdown" (so pressing the button is captured), then edit /etc/acpi/events/powerbtn and comment out the line #action=/etc/acpi/powerbtn.sh, and then enter in terminal: xmodmap -e "keycode 124 = End" This should prevent the power button from doing anything and in the same time map it to the End key.

    – Johano Fierra
    Sep 22 '16 at 17:15






  • 1





    It doesn't help too cause "Power off" event is handled not only by powerbtn.sh script but also by (at least) systemd-logind service (probably, it uses button-power setting you mentioned in your answer). You can find if pidof systemd-logind >/dev/null; then...exit 0 line in powerbtn.sh which means that the script lets systemd-logind to handle "Power off" event by itself when desktop session is active. One thing you are right about — changing button-power value doesn't affect the ability to capture the key but it's already captured by some process (systemd-logind or other).

    – Ezze
    Sep 26 '16 at 8:53










2




2





YES!!! But then there is another thing: how to map it into the «end» key?

– Adam Ryczkowski
Feb 2 '15 at 17:31





YES!!! But then there is another thing: how to map it into the «end» key?

– Adam Ryczkowski
Feb 2 '15 at 17:31




1




1





Entering uncharted territory here, but I think you could just create a xmodmap file config (${HOME}/.xmodmap) and then put this in it: keycode 116 = End, or enter in terminal: xmodmap -e "keycode 116 = End"

– Johano Fierra
Feb 2 '15 at 17:53







Entering uncharted territory here, but I think you could just create a xmodmap file config (${HOME}/.xmodmap) and then put this in it: keycode 116 = End, or enter in terminal: xmodmap -e "keycode 116 = End"

– Johano Fierra
Feb 2 '15 at 17:53















Unfortunately, it doesn't help. It disables capturing of "Power off" button as it seen by xev command and prevents xmodmap to remap it. And by the way, "Power off" button's keycode may be different (124 for my ASUS N751JK).

– Ezze
Sep 21 '16 at 13:26





Unfortunately, it doesn't help. It disables capturing of "Power off" button as it seen by xev command and prevents xmodmap to remap it. And by the way, "Power off" button's keycode may be different (124 for my ASUS N751JK).

– Ezze
Sep 21 '16 at 13:26













It should not disable the ability to capture the button... but how about this. Enter in terminal: gsettings set org.gnome.settings-daemon.plugins.power button-power "shutdown" (so pressing the button is captured), then edit /etc/acpi/events/powerbtn and comment out the line #action=/etc/acpi/powerbtn.sh, and then enter in terminal: xmodmap -e "keycode 124 = End" This should prevent the power button from doing anything and in the same time map it to the End key.

– Johano Fierra
Sep 22 '16 at 17:15





It should not disable the ability to capture the button... but how about this. Enter in terminal: gsettings set org.gnome.settings-daemon.plugins.power button-power "shutdown" (so pressing the button is captured), then edit /etc/acpi/events/powerbtn and comment out the line #action=/etc/acpi/powerbtn.sh, and then enter in terminal: xmodmap -e "keycode 124 = End" This should prevent the power button from doing anything and in the same time map it to the End key.

– Johano Fierra
Sep 22 '16 at 17:15




1




1





It doesn't help too cause "Power off" event is handled not only by powerbtn.sh script but also by (at least) systemd-logind service (probably, it uses button-power setting you mentioned in your answer). You can find if pidof systemd-logind >/dev/null; then...exit 0 line in powerbtn.sh which means that the script lets systemd-logind to handle "Power off" event by itself when desktop session is active. One thing you are right about — changing button-power value doesn't affect the ability to capture the key but it's already captured by some process (systemd-logind or other).

– Ezze
Sep 26 '16 at 8:53







It doesn't help too cause "Power off" event is handled not only by powerbtn.sh script but also by (at least) systemd-logind service (probably, it uses button-power setting you mentioned in your answer). You can find if pidof systemd-logind >/dev/null; then...exit 0 line in powerbtn.sh which means that the script lets systemd-logind to handle "Power off" event by itself when desktop session is active. One thing you are right about — changing button-power value doesn't affect the ability to capture the key but it's already captured by some process (systemd-logind or other).

– Ezze
Sep 26 '16 at 8:53




















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f580902%2fhow-to-change-mapping-for-the-poweroff-key-on-keyboard%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

GameSpot

connect to host localhost port 22: Connection refused

Getting a Wifi WPA2 wifi connection