Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 66 lines (55 sloc) 1.93 KB
#!/usr/bin/env python
from bottle import route, template, run, request, response, CherryPyServer
from cheese import mouse, keyboard
@route('/')
def index():
return template('index')
"""
Mouse and Keyboard update routes
"""
@route('/mouse/moved', method='POST')
def mouse_moved():
x = int(request.POST.get('x'))
y = int(request.POST.get('y'))
print 'Mouse moved! x: %s y: %s' % (x, y)
@route('/mouse/pressed', method='POST')
def mouse_pressed():
button = int(request.POST.get('button'))
mouse.press(button + 1)
print 'Mouse pressed! button: %s' % button
@route('/mouse/released', method='POST')
def mouse_released():
button = int(request.POST.get('button'))
mouse.release(button + 1)
print 'Mouse released! button: %s' % button
@route('/keyboard/pressed', method='POST')
def keyboard_pressed():
key = int(request.POST.get('key'))
ctrl = request.POST.get('ctrl', False)
alt = request.POST.get('alt', False)
shift = request.POST.get('shift', False)
meta = request.POST.get('meta', False)
keyboard.press(key)
print 'Key pressed! key: %s ctrl: %s alt: %s shift: %s meta: %s' % (key, ctrl, alt, shift, meta)
@route('/keyboard/released', method='POST')
def keyboard_released():
key = int(request.POST.get('key'))
ctrl = request.POST.get('ctrl', False)
alt = request.POST.get('alt', False)
shift = request.POST.get('shift', False)
meta = request.POST.get('meta', False)
keyboard.release(key)
print 'Key released! key: %s ctrl: %s alt: %s shift: %s meta: %s' % (key, ctrl, alt, shift, meta)
@route('/static/:file')
def static_file(file):
return open('static/%s' % file)
"""
Launch server
"""
try:
run(host='0.0.0.0', port=1300, server=CherryPyServer)
except ImportError:
# no cherrypy, use SimpleServer (slooooow)
print 'Cherrypy not installed, using SimpleServer instead.'
print 'WARNING: SimpleServer runs much slower!\n'
run(host='0.0.0.0', port=1300)
Jump to Line
Something went wrong with that request. Please try again.