TrendNet TK-207K and Debian 6

This 2-port USB KVM switches between computers when the scroll lock key is pressed twice within two seconds. This works fine under Windows. However, if you're switching between Windows and Linux, you can't switch back. Since I like to keep the KVM out of sight (and in a good cable run) under the desk this is somewhat problematic.

I found a few suggestions online, the majority of which didn't work. Using xset led named 'Scroll Lock' followed by xset -led named 'Scroll Lock' worked but was clumsy. (That is, it appears the the KVM doesn't detect the scroll lock key, but rather the message from the computer to the keyboard that it should turn the scroll lock LED on.) Another post suggested using xbindkeys (and xbindkeys-config) to map a single key to a small shell script that turned the LED on, waited a second, and then turned it back off.

However, I'd been using TrendNet's TK-205K, which used the sequence 'scroll lock, scroll lock, up-arrow' to switch computers for a number of years and didn't want to retrain my muscle memory, so I went looking for a way to actually toggle the scroll lock LED the way that Windows does. It took way too long to notice that xset has a query mode. :( But with that knowledge, I wrote the following simple script, and hooked it up to the scroll lock with xbindkeys-config.

SCROLL_LOCK=`/usr/bin/xset q | /usr/bin/awk '/Scroll Lock/{print $12}'`
if [ ${SCROLL_LOCK} = "on" ]; then
    /usr/bin/xset -led named 'Scroll Lock'
    /usr/bin/xset led named  'Scroll Lock'
exit 0

I haven't looked into solving the problem -- if there is one -- from the console proper, because I practically never use it, but this solution works well from X.