File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # for some reason my usb keyboard misses the first 1 or 2 keystrokes after
3
+ # when it resumes after being idle for a while. The bug is caused by usb
4
+ # autosuspend, but i don't want to fully disable it on my laptop, so here's
5
+ # the workaround to only disable autosuspend on the USB port where the
6
+ # keyboard is connected.
7
+
8
+ DEVICE=" 046a:0010"
9
+
10
+ # make sure this is run as root
11
+ uid=$( id -ur)
12
+ if [ " $uid " != " 0" ]; then
13
+ echo " This script must be run as root"
14
+ exit 1
15
+ fi
16
+
17
+ busnum=$( lsusb | grep " ${DEVICE} " | cut -f 2 -d " " )
18
+ devnum=$( lsusb | grep " ${DEVICE} " | cut -f 4 -d " " | sed -e " s/://" )
19
+
20
+ if [ -z $devnum ]; then
21
+ echo " Keyboard not found"
22
+ exit 1
23
+ fi
24
+
25
+ for f in ` ls /sys/bus/usb/devices/ | grep -v " :" ` ; do
26
+ BUSNUM=$( cat /sys/bus/usb/devices/$f /busnum)
27
+ DEVNUM=$( cat /sys/bus/usb/devices/$f /devnum)
28
+ if [ " $BUSNUM " -eq " $busnum " ] && [ " $DEVNUM " -eq " $devnum " ]; then
29
+ break
30
+ fi
31
+ done
32
+
33
+ echo " Disabling autosuspend on USB $BUSNUM :$DEVNUM , to reenable:"
34
+ echo " echo 2 |sudo tee /sys/bus/usb/devices/$f /power/autosuspend"
35
+ echo -1 > /sys/bus/usb/devices/$f /power/autosuspend
You can’t perform that action at this time.
0 commit comments