Author Topic: [python]Disablekey  (Read 1125 times)

0 Members and 1 Guest are viewing this topic.

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
[python]Disablekey
« on: 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
Code: [Select]
xinput list
Example:
Code: [Select]
[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
Code: [Select]
xinput float 12 and
Code: [Select]
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.
Code: [Select]
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.

Code: (python) [Select]
#!/usr/bin/env python2

import os

os.system("xinput float 13 && xinput float 12")
« Last Edit: May 21, 2014, 03:18:22 pm by techb »
>>>import this
-----------------------------

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: [python]Disablekey
« Reply #1 on: May 21, 2014, 05:41:47 pm »
So, why the hell isn't this just a one-liner shell script?

Code: (Bash) [Select]
#!/usr/bin/sh
xinput float 13 && xinput float 12

This is about as superfluous as writing a C program just to run `ls -al`.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: [python]Disablekey
« Reply #2 on: May 21, 2014, 06:16:31 pm »
So, why the hell isn't this just a one-liner shell script?

Code: (Bash) [Select]
#!/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.
>>>import this
-----------------------------

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: [python]Disablekey
« Reply #3 on: May 21, 2014, 06:41:26 pm »
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.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [python]Disablekey
« Reply #4 on: May 21, 2014, 06:45:31 pm »
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 :)

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
Re: [python]Disablekey
« Reply #5 on: May 21, 2014, 10:40:31 pm »
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
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]