#!/usr/bin/env python # # keyrelay.py # # A quick GTK+ application that relays keystrokes via XTest (using xte). # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ### Edit these variables ### host = "persephone" display = ":0" command = "ssh mythtv@%s \"DISPLAY=%s xte\"" % (host, display) # command = "DISPLAY=%s%s xte" % (host, display) ##### Software follows ##### import os, sys import gtk xte = os.popen (command, 'w') def key_press_cb (eventbox, event): if event.state != 0: return False # sys.stderr.write ("keydown %s\n" % gtk.gdk.keyval_name (event.keyval)) xte.write ("keydown %s\n" % gtk.gdk.keyval_name (event.keyval)) xte.flush () return True def key_release_cb (eventbox, event): if event.state != 0: return False # sys.stderr.write ("keyup %s\n" % gtk.gdk.keyval_name (event.keyval)) xte.write ("keyup %s\n" % gtk.gdk.keyval_name (event.keyval)) xte.flush () return True def main (): window = gtk.Window () window.set_title ("Key Relay") window.set_default_size (200, 200) label = gtk.Label () label.set_markup ("Key Relay\n\nKeystrokes typed into this window will be relayed to the X server %s%s" % (host, display)) label.set_justify (gtk.JUSTIFY_CENTER) label.set_line_wrap (True) window.add (label) window.connect ("key-press-event", key_press_cb) window.connect ("key-release-event", key_release_cb) window.connect ("destroy", gtk.main_quit) window.show_all () gtk.main () if __name__ == '__main__': main ()