Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I like to put my displays to powersave/standby mode when I leave the computer for a while. It would be ok if it weren't for oversensitive mouse. Sometimes the driver reads in some movement that's not visible to the naked eye (the cursor, that is) and it breaks the power save. It would wait for another 10 minutes before going back to its standby.

My workaround is the following script bound to C-S-q:

xlock -startCmd 'xset dpms 2 2 2' -endCmd 'xset dpms 600 1200 1300' -mode blank -echokeys -timeelapsed +usefirst

By using xset I set the values to 2 seconds each before going to standby. It's not nice, anyway. Sometimes there are cool fortunes that I want to read before typing in the password. I could keep the cursor moving but it's cludgy. (By the way, xlock's option mousemotion doesn't help -- it just hides the cursor but the displays fire up nevertheless.)

So the question: is there a way to make displays go standby and stay there until a keyboard key is pressed? I'm running gentoo and recent Xorg, but I hope the answer doesn't have to be distro-specific.

Basically the answer can be as simple as how to enable/disable mouse within command line? It think that would do the job if DPMS doesn't know the idea.

share|improve this question
If it's the hardware that's the problem, then the hardware could be the solution - flip the mouse over until you want to use it. (Okay, that was sarcastic, but you get the point). – new123456 Jun 24 '11 at 17:11
Not a bad suggestion but it would still read something while being upside down :) – progo Jun 24 '11 at 17:12
Even the most sensitive optical mice won't register any movement without an object of some sort within about an inch or so of the sensor. If it's a mechanical mouse, just pop the ball out to achieve the same effect. – Shinrai Jun 24 '11 at 17:23
Eh. Let's think of something that doesn't require flipping the mouse. :) – progo Jun 24 '11 at 17:25
Nah, you're right, it's a good question (and that's why I upvoted it). But I agree with @new123456 that sometimes a mechanical solution is easier (and it may be that nobody comes through for you on this - I'm not a Linux guy so I sure can't). – Shinrai Jun 24 '11 at 17:40
up vote 3 down vote accepted

There's a great post by @pbm that covers this, over on the Unix SE site.

In short, first use xinput list to get the device ID for your mouse, and then use

xinput --set-prop [ID#] "Device Enabled" "0"


xinput --set-prop [ID#] "Device Enabled" "1"

to disable and enable the mouse.

I've just tested these here by disabling the mouse and then calling xset dpms force standby. Waving the mouse around for several seconds did nothing to disturb the screen, but pressing a single key worked fine. Using the second command then returned the mouse back to normal, including the "constant deceleration" setting that my default startup scripts set for me.

You should be able to pass these two commands to the -startCmd and -endCmd options to xlock to get what you're after.

share|improve this answer
Does perfectly the right thing! Thanks a ton :) – progo Jun 30 '11 at 7:38
Instead of using --set-prop option along with “Device Enabled/Disabled” property, one can also use --enable and --disable options as well, e.g. xinput --enable [device] and xinput --disable [device]. – thebodzio Feb 7 '13 at 3:37

I do it this way in Ubuntu:


# allow only one instance
r=$(pidof -x -o $$
set -- $r
if [ "${#@}" -ge 1 ]; then
    echo "Script already running. Exit..."

dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" | ( while read line; do
    if echo $line | grep "boolean true" &> /dev/null; then
            xinput --set-prop "Dell Premium USB Optical Mouse" "Device Enabled" "0"
            xset dpms force off
            xinput --set-prop "Dell Premium USB Optical Mouse" "Device Enabled" "1"
done )

Some notes:

  • I'm also forcing monitor off.
  • Better use the full name instead of ID.

I hope that this helps.

share|improve this answer
Looks good but I don't use dbus or gnome so won't try it out. – progo Oct 25 '12 at 13:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.