[SOLVED - The given example contains the answer!] I am trying to implement a program that runs in full screen mode and does not allow the user to enter a user (mouse or keyboard), because it simply responds to UDEV signals when a USB flash drive or CD is inserted -disk. I want to prevent the user from laying the keyboard / mouse and doing something strange with the workstation. The only time a keyboard is required is when an administrator inserts a keyboard and press CTRL-T, so my program opens a terminal window.
I work with Debian (Squeeze) + Gnome-Desktop-Environment.
I tried to use XLib, which is great for capturing all keyboard events, but I canโt open my keyboard when my program opens my terminal (which also works fine), so the user cannot use the shell, the selection is disabled.
Here are some important code snippets:
class ScanWSClient(gtk.Window):
def __init__(self, url):
disp = Display()
self.display = disp
gtk.Window.__init__(self)
self.terminal_window = None
self.kb_handler = KeyboardHandler(self).start()
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()
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 streaming KeyboardHandler, I retrieve all the events placed in xlib and check with my handle_event function if CTRL-T is pressed. If so, I open the terminal and remove the keyboard (doesn't work):
self.scanws_client.display.ungrab_keyboard(1, X.CurrentTime)
Who can tell me why I canโt open my stupid keyboard? (this question is in the cookie;))
source
share