How do I 'lock the keyboard' to prevent any more keypresses being sent on X11/Linux/Gnome?

I am writing an anti-RSI/typing break programme for Ubuntu Linux in python. I would like to be able to "lock the keyboard" so that all keypresses are ignored until I "unlock" it. I want to be able to force the user to take a typing break.
I would like some programmatic way to "turn off" the keyboard (near instantaneously) until my programme releases it later (which could be 0.1 sec → 10 sec later). While I have "turned off the keyboard", no key presses should be sent to any
windows, window managers, etc. Preferably, the screen should still show the same content. The keyboard should be locked even if this programme is not at the forefont and does not have focus.
Some programmes are able to do this already (e.g. Work Rave)
How do I do this on Linux/X11? (Preferable in Python)

class KeyboardLocker:
def __init__(self, serio=0):
self._on = False
self.serio = serio
def on(self):
return self._on
def write_value(self,path, value):
with open(path, "a") as f:
f.write(value)
def toggle(self):
if self.on():
self.turn_off()
else:
self.turn_on()
def description(self):
path = '/sys/devices/platform/i8042/serio%d/description' % (self.serio,)
with open(path, "r") as f:
description = f.read()
return description
def turn_on(self):
try:
self.write_value('/sys/devices/platform/i8042/serio%d/bind_mode' % (self.serio,),
'auto')
except IOError, e:
self._on = False
raise
else:
self._on = True
return self.on()
def turn_off(self):
try:
self.write_value('/sys/devices/platform/i8042/serio%d/bind_mode' % (self.serio,),
'manual')
self.write_value('/sys/devices/platform/i8042/serio%d/drvctl' % (self.serio,),
'psmouse')
except IOError, e:
self._on = True
raise
else:
self._on = False
return self.on()
if __name__ == "__main__":
kl = KeyboardLocker(serio=0)
device = kl.description()
print "We got a lock on", device
proceed = raw_input("Do you want to proceed? (y/n)").lower().startswith("y")
import sys
if not proceed: sys.exit(1)
kl.turn_off()
import time
wait = 5
print "Sleeping few seconds...", wait
time.sleep(wait)
print "Voila!"
kl.turn_on()
raw_input("Does it work now?")
Tested on Linux Mint 12, X11, HP Laptop, Gnome. Not sure if any of that matters though :)
UPDATE Added an option to change the path, e.g. "serio0" or "serio1". And prints the description, for me serio0 gave me: i8042
KBD port, most likely if you have "KBD" in it, it's right, continue, otherwise I give you no guarantee :)

Similar Messages

  • How do I change the email that my security info is being sent to?

    I'm trying to purchase something on a new laptop and my account is asking that I answer some security questions. I made my apple account about 3 years ago and I cant remember the answers to my security questions. I also have no idea what e-mail the security info is being sent to when I click on the link bellow the security questions since I don't remember ever signing up to a gmail account though that's what it shows. I just want to know how I can change the e-mail that the security info is being sent to.

    You cannot and need to contact Apple to get the questions reset. Click here, phone them, and ask for the Account Security team, or fill out and submit this form.
    (95673)

  • Auto locking the keyboard in curve 9300

    Hello, i would like to know if there is a way, with the phone by itself or with any app, to auto lock the keyboard.
    In any nokia phone (the old ones, not smartphones) you can set it to auto lock after X seconds you didnt use the phone. Thats what I need.
    The thing is, i have the phone locked in my pocket. I recieve a call, I answer it, and when I finish, the phone stay unlocked. I forguet to lock it again, put in my pocket, and hell unleashes (phone calls, messages, and more without wanting).
    So, I want my phone to lock itself after 15 sefonds in stand by. And to stay locked after i recieve a call.
    Thanks in advance.

    Hey Mr elancio,
    The device does not have a setting
    to lock the key board automatically; you can set a security password to
    lock the device, but you will need to use a password to unlock each time:
    Go to Options> Password> Change the Password field to Enabled.
    Set the Lock after time and check off allow out going calls while locked
    I hope this helps.
    -HB
    Come follow your BlackBerry Technical Team on twitter! @BlackBerryHelp
    Be sure to click Kudos! for those who have helped you.Click Solution? for posts that have solved your issue(s)!

  • I use a French bluetooth keyboard how do i lock the numbers for doing calculations? Does anybody know? i.e. the numbers are above the top row of keys and you have to use the shift key to access them.  You can't use the cap lock key to lock the numbers.

    How do I lock the numbers on a French keyboard if I'm using a small blue tooth keyboard with no number pad?

    How do I lock the numbers on a French keyboard if I'm using a small blue tooth keyboard with no number pad?

  • How to lock the keyboard - macbook

    I know most people are trying to UNlock their keyboards....
    My wife uses her macbook to show movies to my 3 and 4yr old while traveling. But the kids can't helpthemselves and after 5 minutes try and "type like mama". which inevitably stops the DVD causes another program to open or something. Anyone with kids knows this instant "mayhem and change" on the screen only encourages the behavior.
    Good kids.. but who can resist playing with a Mac, regardless of how old they are
    Is there a way to lock the keyboard to that only pressing a certain combo will enable it again? (and keep programs/DVD running)
    Thanks
    -mosermac2

    There's not a function to turn off the keyboard however you can turn mouse keys on and most of the keyboard keys will be ignored.
    The shortcut for this is pressing Option five times.  Do it again to turn mouse keys off.
    Also can be set in System Preferences > Universal Access > Mouse & Trackpad tab.
    Regards,
    Captfred

  • HT201304 How can i lock the General or setting to prevent other people open it?

    How can i lock the General or setting to prevent other people open it?

    Leliforever, cheek you list of installed add-ons, the Ask toolbar can be installed without the users knowledge.
    For checking other extensions that may cause this, follow the procedure in this link - https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • How can I lock the file in use

    Dear All, I transfer the large text file to Solaris 10 server and copy the this file with transfer not success to another path. but I can open the file with end of file. How can I lock the file with transfer not successfully.

    Locking on UNIX is cooperative, not manditory. That means that all applications need to check for the lock explicitly and then not use the file if the lock exists.
    But if something is accessing the file beyond your control, locking isn't going to prevent it.
    If you do control all the access points, then take a look at lockf or flock functions.
    Darren

  • HT4623 How do I get The keyboard to appear?

    How do I get the keyboard to appear?  I seem to have lost the use of it.

    Usually, just tap in a text box.
    however if you have a bluetooth attached and active then it'll prevent your onscreen keyboard from popping up

  • Is it possible to lock the keyboard please?

    Hi
    I've got a Pavilion dv6 notebook and would like to know if its possible to intentionally lock the keyboard. This is to prevent my 3 year old daughter from accidentally pressing the keys whilst she watches a DVD.
    A speedy response would be appreciated as we're heading overseas tomorrow (Wed 9 Feb) and I'd like to know the answer before we fly.
    thanks!

    Not really.
    Windows+L locks the laptop and requires a passsword. T
    he problem is that  the notebook can't be used while it is locked.
    You woud be better off buying a travel DVD player if you want to avoid the risk of a three year old's curiousity.
    Best regards,
    erico
    ****Please click on Accept As Solution if a suggestion solves your problem. It helps others facing the same problem to find a solution easily****
    2015 Microsoft MVP - Windows Experience Consumer

  • How do you lock the ipad so only one app can be used

    I want to force a student to communicate using an ipad communication app.  I want the only thing on the screen to be that one app.  How do I lock the app so it is the only one that can be used on the ipad?   Is there a way to lock a page?  ie when he has navigated to the correct page to prevent the child from exiting and make him make a choice from that page?
    Thanks!

    You can lock an iPad to a given app via Guided Access:
    http://support.apple.com/kb/HT5509
    To try and lock a web browser to a single page you'll need to investigate third-party browsers such as MobiCIP or the McGruff browser and see if they allow you to lock to a single page. Safari in iOS 6 or earlier has no controls and in iOS 7 allows you to restrict to a given site or set of sites but not to a single web page.
    Regards.

  • How do you lock the screen on iphone 4?

    How do you lock the screen on iphone 4 while on a call? I mute calls, activate face time and I have even called someone by accident during a call. I know there has to be a way to fix this. Please HELP!

    It locks automatically when you hold it to your head.
    If it fails to do this, then remove the case and see if it solves it.
    If it does not, then do the basics - restart, reset, restore.
    If that does not solve it, then make an appointment at the genius bar.

  • Is it possible to lock the keyboard of a client from a server using java

    please explain wheterit is possible to lock the keyboard of a client from a server using java

    You want to process code on one machine, and thereby lock the keyboard on another machine? No, that's not possible. It is extremely far from possible.
    Of course, if the client is running software with security holes in it you might hack into it and crash the thing. This will lock up the keyboard pretty good. I hope that's not what you want ...
    Or are you talking about a setup where you already have code running on the client, and some sort of communication between client and server? In that case what you need to know is whether it is possible to lock the keyboard at all. Once you have figured that out, it is trivial to add the communication code to have the server software tell the client software to lock the keyboard.
    So what do you mean with "lock the keyboard"? It's pretty easy to remove/disable all keyboard related listeners in your own application. It's a lot harder (and AFAIK impossible with pure java) to disable alt-tabbing out of the application. And impossible, except from exploiting security holes, to lock the ctrl-alt-delete-combination on windows machine.

  • On my new iPhone, at the Apps store, I tried to make a purchase, the popup screen shows my Apple ID and asks for my password, but no keyboard appears so that I can enter the password.  How do I get the keyboard to appear??

    On my new iPhone, at the Apps store, I tried to make a purchase, the popup screen shows my Apple ID and asks for my password, but no keyboard appears so that I can enter the password.  How do I get the keyboard to appear??

    On your iPad, delete the existing account then sign back in with the new ID and password.

  • How do I get the keyboard on my macbook pro to light up?

    how do i get the keyboard on my macbook pro to light up?

    Welcome to Apple Support Communities
    What MacBook Pro have you got? Only Unibody MacBooks Pro (Late 2008 and newer) have a backlit keyboard. If you have one of these MacBooks Pro, you can set up its illumination in System Preferences > Keyboard. See > http://support.apple.com/kb/ht4882

  • How can I lock the object in my dock?

    Members in my family continue to accidently drag objects off the dock on my powerbook by accident.
    How can I "lock the dock"?
    Thanks.

    You can't. This is a real problem when you accidentally drag 300+ files onto an application icon but miss...
    Matt

Maybe you are looking for

  • How do I install an app. on my Iphone again ?

    Yesterday I plugged my iphone to the pc, and it said I needed to upgrade it to ios 4.0. I did, and suddenly i pressed on something, and it deleted everything on my phone, including contacts and app. So how do I install the app. I have bought on my ph

  • Submit to SAP Button in Adobe Forms

    Hi, I have an adobe form and i have embedded it in to a Web-dynpro view.Now i have placed a "submit to sap " button on this form so that when the user clicks on this i save the contents of this form as an attachment. My Issue is that the control does

  • N96 Firmware Updates

    I have got N96 today and I want to update the firware from v12 to v20 but FOTA says v30 is available,please any help about this cuz under v30,the feature is supported.I prefer v20 to 30 Solved! Go to Solution.

  • BB usage monitor for 1 month ?

    OK, just found the account linked usage monitor, and can see what has been recorded month to date. Allowing for the fact it's a new tool, it would be nice to see previous months' data too, to assess trending vs. best service selection. I can't see a

  • Stored Procedure executes on two different schemas in Oracle 8i

    Can I Create a Stored Procedure that access table from two different schemas? For Example I have created this Stored Procedure on SCHEMA_ONE CREATE OR REPLACE PROCEDURE SP_DEMO IS BEGIN INSERT INTO SCHEMA_ONE.COUNTRY_ONE(COUNTRY_NAME) SELECT COUNTRY_