Remote Virtual Keyboard Script
#1
This python script will take key presses into the terminal and send them to XBMC via the HTTP API. While this can be useful for entering text without fumbling with a remote to use the on screen keyboard, it is even more useful for keying in automatically generated passwords used with password managers, since these can simply be pasted into the terminal to enter the password into XBMC.

I've tested this script doing remote control from OSX of XBMC, but should work with the script running locally, via SSH. Simply edit the variables at the top of the script to suit your setup.

Arrow keys and ASCII characters should work.

Let me know if there are any problems.

Code:
#!/usr/bin/python
import curses
import urllib, urllib2
import base64

hostname = "localhost"
port =  "8080"
username = ""
password = ""

if port != '':
    hostname = hostname + ":" + port

def sendKey(key):
    baseUrl = "http://" + hostname + "/xbmcCmds/xbmcHttp?command=SendKey(" + key + ")"
    req = urllib2.Request(baseUrl)
    if password != '':
        base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
        authheader =  "Basic %s" % base64string
        req.add_header("Authorization", authheader)
        
    handle = urllib2.urlopen(req, timeout=10)
    handle.close()        

stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(1)

try: # in case you ever want to leave, ctrl+c
    while True:
        letter = stdscr.getch()
        if letter < 256:
            if letter == 10:
                letter = 13
            elif letter == 127:
                letter = 8
            sendKey(hex(0xf100+int(letter)))
        elif letter == curses.KEY_UP:
            sendKey(hex(270))    
        elif letter == curses.KEY_DOWN:
            sendKey(hex(271))    
        elif letter == curses.KEY_LEFT:
            sendKey(hex(272))
        elif letter == curses.KEY_RIGHT:
            sendKey(hex(273))
except: # will clean up for curses
    curses.nocbreak()
    stdscr.keypad(0)
    curses.echo()
    curses.endwin()
Reply
#2
Thanks for the script. Just tested it on my Ubuntu laptop and it's working great.
Reply

Logout Mark Read Team Forum Stats Members Help
Remote Virtual Keyboard Script0