-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote.py
More file actions
executable file
·50 lines (38 loc) · 1.25 KB
/
Copy pathremote.py
File metadata and controls
executable file
·50 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env jython
from java.awt import Robot
from java.awt.event import KeyEvent
from java.lang import System
import sys
import socket
import SocketServer
import SimpleHTTPServer
DEFAULT_PORT = 8000
# http://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyEvent.html
class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
print self.path
if self.path == '/up':
rbt.keyPress(KeyEvent.VK_PAGE_UP)
rbt.keyRelease(KeyEvent.VK_PAGE_UP)
elif self.path == '/down':
rbt.keyPress(KeyEvent.VK_PAGE_DOWN)
rbt.keyRelease(KeyEvent.VK_PAGE_DOWN)
else:
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def get_ip():
if not System.getProperty('os.name').startswith('Linux'):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 53)) # Google's public DNS server
ip = s.getsockname()[0]
s.close()
else:
ip = socket.gethostbyname(socket.gethostname())
return ip
rbt = Robot()
if len(sys.argv) == 2:
PORT = int(sys.argv[1])
else:
PORT = DEFAULT_PORT
httpd = SocketServer.ThreadingTCPServer(('', PORT), MyHandler)
print '%s:%d' % (get_ip(), PORT)
httpd.serve_forever()