EvilZone
Programming and Scripting => Scripting Languages => : techb May 21, 2014, 03:17:52 PM
-
My cat likes to sleep on my keyboard on my laptop. It used to cause problems but I have a solution now.
My laptop is on a computer desk and I use a usb keyboard and mouse and not the built in stuff. The keyboard and mouse I use are on a slider that goes under the desk when I'm not using the computer, typical setup. Since I usually leave my laptop running to seed and media serve and what not, my cat sleeping on it was an issue. There is a simple fix for it though. You can disable them in linux vvia xinput.
First you need to find out what they are listed as by using xinput list
Example:
[techb@arch ~]$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ MOSART Semi. 2.4G RF Keyboard & Mouse id=10 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=13 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Power Button id=8 [slave keyboard (3)]
↳ MOSART Semi. 2.4G RF Keyboard & Mouse id=9 [slave keyboard (3)]
↳ HP Webcam-101 id=11 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=12 [slave keyboard (3)]
↳ HP WMI hotkeys id=14 [slave keyboard (3)]
As you can see the things I want to disable are id=12 and id=13; AT Translated Set 2 keyboard and SynPS/2 Synaptics TouchPad respectively. To do this, we simply put them in a floating state using xinput float 12
and xinput float 13
.
Afterward they will not effect anything if they are pressed or used. To gain use again, we reattach them to the respected masters.You can see the id of the pointer and keyboard master in the `xinput list` output. xinput reattach 12 3 && xinput reattach 13 2
A simple python script to do this with just a single command, I only ever need to disable them, so reattaching is left out, feel free to add it. Also, a simple bash script or similar could just as easy do the same thing.
Make a file in /usr/bin and call it what you want, I call mine disablekey, add the following and chmod it for execution.
#!/usr/bin/env python2
import os
os.system("xinput float 13 && xinput float 12")
-
So, why the hell isn't this just a one-liner shell script?
#!/usr/bin/sh
xinput float 13 && xinput float 12
This is about as superfluous as writing a C program just to run `ls -al`.
-
So, why the hell isn't this just a one-liner shell script?
#!/usr/bin/sh
xinput float 13 && xinput float 12
This is about as superfluous as writing a C program just to run `ls -al`.
Because I chose python that's why. Please tell me why it has to be a one line shell script? I clearly stated that this could be done be done in bash or what ever user said chooses. If you know how to, then do it. People might not know how to disable a keyboard to keep a cat from fucking with it. So here it is, I never seen your post on disabling a keyboard or mouse now did I?
It has a use, bash, or python, or pearl , or what ever... Nothing ill was stated my my OP, so why try and flame? Yes Bash can do it, and I posted that when I wrote it, but I chose to python it up and sand seems spew in everyones panties. Sorry for giving an example and using something other than the "simplest method" to achieve something.
The proud horse still stand strong. Go with vezzy, he clearly know the best.
-
The point here is that you're adding a completely unnecessary level of indirection. Why invoke the shell from an external interpreter when you can just invoke the shell directly?
I understand writing Python scripts for something more complex. But when it's just a bunch of os.system() calls that string together sequential shell commands, that's just idiotic.
-
Whoah now! take it easy guys.
@techb: vezzy does it to everyone. His fancy vocabulary and rude manners make him special :P
No more flame or this will get locked :)
-
Well i didn't know that, at least i have never done it or had need to do it.
Better find a way to do it in windows then write one small python script for both linux and windows. <3