Skip to content

nojusmorkunas/disable-mouse-wakeup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Disable Mouse Wake-up

A Bash script that prevents USB mice from waking your laptop while preserving keyboard wake-up functionality.

When your laptop is suspended/sleeping, connected USB mice can accidentally wake it up with the slightest movement. This was very annoying, especially when my table is pretty wobbly and would trigger wake up all the time. This script solves that problem by disabling wake-up for mice while keeping keyboard wake-up enabled.

Features

  • Automatically detects connected USB mice
  • Disables wake-up immediately for currently connected mice
  • Creates persistent udev rules so settings survive reboots and reconnections
  • Preserves keyboard wake-up functionality
  • Safe to run (requires explicit confirmation)
  • Color-coded output for better readability

Requirements

  • Linux system with udev
  • Bash
  • sudo privileges
  • lsusb command (usually from usbutils package)

Installation

  1. Clone or download the script:
git clone https://github.com/nojusmorkunas/disable-mouse-wakeup.git
cd disable-mouse-wakeup
  1. Make the script executable:
chmod +x disable-mouse-wakeup.sh

Usage

Simply run the script (do NOT use sudo directly):

./disable-mouse-wakeup.sh

The script will:

  1. Scan for connected USB mice
  2. Show you what it found
  3. Ask for confirmation
  4. Disable wake-up for detected mice
  5. Create a udev rule at /etc/udev/rules.d/90-disable-mouse-wakeup.rules

Example Output

 Disable Mouse Wake-up Script

Scanning for USB mice...
Found mouse: Logitech USB Receiver (046d:c52b)

This script will:
1. Immediately disable wake-up for currently connected mice
2. Create a udev rule to automatically disable wake-up for these mice when plugged in
3. Preserve keyboard wake-up functionality

Continue? (y/N):

How It Works

  1. Detection: Scans lsusb output for devices matching common mouse patterns:

    • Device name contains "mouse"
    • Known mouse vendor IDs (Logitech, etc.)
    • Wireless dongles and receivers
  2. Immediate Action: Writes disabled to /sys/bus/usb/devices/*/power/wakeup for detected mice

  3. Persistence: Creates a udev rule that automatically applies the setting whenever the mouse is plugged in

Undoing Changes

To restore mouse wake-up functionality:

sudo rm /etc/udev/rules.d/90-disable-mouse-wakeup.rules
sudo udevadm control --reload-rules

Then manually re-enable wake-up if needed:

echo 'enabled' | sudo tee /sys/bus/usb/devices/*/power/wakeup

Troubleshooting

Mouse not detected

The script uses heuristics to detect mice. If your mouse isn't detected, you can manually find its vendor/product ID:

lsusb

Then manually create a udev rule in /etc/udev/rules.d/90-disable-mouse-wakeup.rules:

SUBSYSTEM=="usb", ATTR{idVendor}=="XXXX", ATTR{idProduct}=="YYYY", ATTR{power/wakeup}="disabled"

Replace XXXX and YYYY with your mouse's vendor and product IDs.

Changes not persisting

If the mouse still wakes the system after a reboot:

  1. Verify the udev rule exists: cat /etc/udev/rules.d/90-disable-mouse-wakeup.rules
  2. Reload udev rules: sudo udevadm control --reload-rules
  3. Reconnect the mouse

Script requires sudo

Do NOT run the script with sudo directly. Run it as a normal user and it will prompt for sudo when needed. This is a safety feature.

Supported Mouse Vendors

The script recognizes these common vendor IDs:

  • 046d - Logitech
  • 1bcf - Sunplus Innovation Technology
  • 258a - Roytek
  • 093a - Pixart Imaging

And devices with names containing:

  • "Mouse"
  • "Wireless Dongle"
  • "Receiver"

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

About

A Bash script that prevents USB mice from waking your laptop while preserving keyboard wake-up functionality.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages