Example #1
0
    def control(self):
        """Control an X11 keyboard.  Press Ctrl-C to stop."""

        # current display
        root = Display().screen().root

        # we tell the X server we want to catch keyPress event
        root.change_attributes(event_mask = X.KeyPressMask)

        # Inform X11 of which keys we'll be trapping
        keys = self.keys
        for keycode in keys:
            root.grab_key(keycode, X.AnyModifier, 1,
                          X.GrabModeAsync, X.GrabModeAsync)

        # Endless loop which listens for events
        next_event = root.display.next_event
        KeyPress = X.KeyPress
        try:
            while 1:
                event = next_event()
                if event.type == KeyPress:
                    # For KeyPress events, event.detail is the keycode
                    keys[event.detail]()
        except KeyboardInterrupt:
            pass
Example #2
0
def main():
	import_scripts()
	# current display
	root = Display().screen().root

	# we tell the X server we want to catch keyPress event
	root.change_attributes(event_mask = X.KeyPressMask)

	for keycode in keys:
		root.grab_key(keycode, X.AnyModifier, 1,X.GrabModeAsync, X.GrabModeAsync)
	
	try:
		GtkMain().start()
#		thread.start_new_thread( gtk.main, () )
		while 1:
#			gtk.main_iteration()
#			if root.display.pending_events():
			event = root.display.next_event()
			handle_event(event)
	except Exception, inst:
		print 'Error: %s' % inst