Skip to content

Instantly share code, notes, and snippets.

@DanBrink91
Created August 24, 2014 02:59
Show Gist options
  • Save DanBrink91/ebf2a881aa5ac6d6749a to your computer and use it in GitHub Desktop.
Save DanBrink91/ebf2a881aa5ac6d6749a to your computer and use it in GitHub Desktop.
socket client for my desktop, tells the desktop where to click based on keypresses
import socket
import sys
# For getch...
import tty
import termios
HOST = '192.168.1.8'
PORT = 8888
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((HOST, PORT))
except:
print "problems connecting"
sys.exit()
options = {
# Non-fullscreen commands
'q' : "1766,793.", # pause/play
'w' : "2630,799.", # full screen
'e' : "1803,787.", # next episode
'r' : "1882,801.", # skip to ~2:00
# Fullscreen commands
'z' : "1616,1002.", # pause/play
'x' : "2797,1005.", # full screen
'c' : "1651,1004.", # next episode
'v' : "1760,1011.", # skip to ~2:00
}
# Read a keypress without waiting for a \n or enter key
def _getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
while True:
c = _getch()
if c=='p':
s.send("die.")
s.close()
sys.exit()
if c in options:
print "OPTION!"
s.send(options[c])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment