Created
November 26, 2018 04:18
-
-
Save arpruss/26debadb9eb3491062166014f5fee26e to your computer and use it in GitHub Desktop.
espremote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Volume and pause/play in Netflix and Acorn with Philips 642 DVD remote | |
# PageUp/Down with projector remote | |
import win32com.client | |
import win32api, win32con, win32gui | |
from espremote import ESPRemote | |
try: | |
from showtime import showtime | |
except: | |
pass | |
r = ESPRemote() | |
print("Thingy on "+str(r.address)+":"+str(r.port)) | |
shell = win32com.client.Dispatch("WScript.Shell") | |
shell.AppActivate("Chrome") | |
width = win32api.GetSystemMetrics(0) | |
height = win32api.GetSystemMetrics(1) | |
lastTime = 0 | |
prevData = None | |
for event in r.getevents(): | |
if event.format == "UNKNOWN": | |
continue | |
title=win32gui.GetWindowText(win32gui.GetForegroundWindow()) | |
repeat = event.time < lastTime + 500 | |
if event.data == 0xFFFFFFFF: | |
event.data = prevData | |
else: | |
prevData = event.data | |
data = event.data & 0xFFF | |
if data == 0xe1724cb3 or data == 0x45c or data == 0x42c or event.format == "MAGIQUEST" or event.data == 0x2fd01fe or event.data == 0xe1728c73: | |
if not repeat: | |
if title.startswith("Acorn"): | |
win32api.SetCursorPos((500,500)) | |
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 500,500, 0, 0) | |
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 500,500, 0, 0) | |
win32api.SetCursorPos((width-1,500)) | |
else: #if title.startswith("Netflix"): | |
shell.SendKeys(" ") | |
elif data == 0x458 or event.data in (0x2fdd827, 0x2fd58a7, 0xe172c837): | |
shell.SendKeys("\xAF") | |
elif data == 0x459 or event.data in (0x2fdf807, 0x2fd7887, 0xe17228d7): | |
shell.SendKeys("\xAE") | |
elif data == 0x40c: | |
exit() | |
elif data == 0x40f or event.data == 0x2fd1ae5: | |
if not repeat: | |
try: | |
showtime() | |
except: | |
pass | |
elif event.data == 0x16e948b7: | |
shell.SendKeys("{PGUP}") | |
elif event.data == 0x16e918e7: | |
shell.SendKeys("{PGDN}") | |
else: | |
print(hex(event.data)) | |
lastTime = event.time | |
#shell.SendKeys("^a") # CTRL+A may "select all" depending on which window's focused | |
#shell.SendKeys("{DELETE}") # Delete selected text? Depends on context. :P | |
#shell.SendKeys("{TAB}") #Press tab... to change focus or whatever |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment