[SOLVED - Provided example contains the answer!] I am trying to implement a program which is started in fullscreen and does not allow any userinput (wether mouse nor keyboard) because it just reacts on UDEV-Signals, when a usb-stick or cd is inserted. I want to prevent, that a user puts in a keyboard / mouse and does somethin weird with the workstation. The only case, that a keyboard is needed, is when an administrator inserts a keyboard and presses CTRL-T, so my program opens a terminal-window.
I work with a Debian (Squeeze) + Gnome-Desktop-Environment.
I tried to use XLib, which works fine for grabbing all Keyboard-Events, but I cannot ungrab my keyboard, when my program opens my terminal (which works also perfectly), so the user cannot use the shell unless the keyboard-fetching is turned off.
here are some crucial code-fragments:
class ScanWSClient(gtk.Window):
def __init__(self, url):
# current display
disp = Display()
self.display = disp
gtk.Window.__init__(self)
self.terminal_window = None
self.kb_handler = KeyboardHandler(self).start()
#self.fullscreen()
self._browser= webkit.WebView()
self.add(self._browser)
self.connect('destroy', gtk.main_quit)
self._browser.open(url)
self.show_all()
class KeyboardHandler(threading.Thread):
def __init__(self, scanws_client):
super(KeyboardHandler,self).__init__()
self.running = True
self.daemon = True
self.terminal_window = None
self.scanws_client = scanws_client #
def run(self):
root = self.scanws_client.display.screen().root
while self.running:
event = root.display.next_event()
self.handle_event(event)
time.sleep(1)
def handle_event(self,aEvent):
keycode = aEvent.detail
state = aEvent.state
key_type = aEvent.type
if keycode == 28 and key_type == X.KeyPress:
if self.scanws_client.terminal_window == None:
self.scanws_client.terminal_window = TerminalWindow(self.scanws_client, "Administrative Shell started...Type *exit* to return to the locked workstation")
else:
self.scanws_client.terminal_window.present()
self.scanws_client.display.flush() #THIS FLUSH IS NECESSARY TO UNGRAB THE KEYBOARD LATER ON!!!
self.scanws_client.display.ungrab_keyboard(1, X.CurrentTime)
print "Key: %s / Mask: %s / Type: %s" % (keycode, state, key_type)
print self.scanws_client.terminal_window
In my threaded KeyboardHandler, I fetch all xlib-queued events and check with my function "handle_event", if there is CTRL-T pressed. If so, I open my terminal and ungrab my keyboard (doesnt work):
self.scanws_client.display.ungrab_keyboard(1, X.CurrentTime)
Who can tell me why I cannot ungrab my silly Keyboard? (this question is cookie provided ;) )