# -*- coding: utf-8 -*-
import time
import speech
import subprocess
import win32com.client
from zoomUUSee import zoomUUSee
"""author:alex8224 天气冷了,全屏麻烦,随后写的,方便偷懒"""
cmdDict=None
wsh=win32com.client.Dispatch("WScript.Shell")
def voiceCallBack(phrase,listene):
funcptr=cmdDict[phrase]
if funcptr:
funcptr()
def goodbye(listener):
listener.stoplistening()
def listenSong():
#subprocess.Popen("D:\Program Files\KuGou\KuGou2010\KuGoo.exe")
pass
def stopSong():
"""发送ctrl+alt+s"""
wsh.SendKeys("^%{F5}")
def nextSong():
"""发送ctrl+alt+right"""
wsh.SendKeys("^%{RIGHT}")
def prevSong():
"""发送ctrl+alt+left"""
wsh.SendKeys("^%{LEFT}")
def plusSound():
"""发送ctrl+alt+up"""
for i in range(5):
wsh.SendKeys("^%{UP}")
time.sleep(.5)
def jianSound():
"""发送ctrl+alt+down"""
for i in range(5):
wsh.SendKeys("^%{DOWN}")
time.sleep(.5)
def shutdownPC():
stopSong()
subprocess.Popen("shutdown -s -t 180")
def cancelshutdown():
subprocess.Popen("shutdown -a")
def myPC():
subprocess.Popen("explorer c:\\")
if __name__ == "__main__":
global cmdDict
cmdDict={u'全屏播放':zoomUUSee,u'再见':goodbye,u'听歌':listenSong,u'睡觉啦':shutdownPC,u'大点':plusSound,u'小点':jianSound,u'下':nextSong,\
u'上':prevSong,u'取消':cancelshutdown,u'不听':stopSong}
listener=speech.listenfor(cmdDict.keys(),voiceCallBack)
while listener.islistening():
time.sleep(1)
# -*- coding: utf-8 -*-
import win32api,win32gui,win32con,time
def zoomUUSee():
title=u"UUSee网络电视2008".encode("gbk")
handle=win32gui.FindWindow(None,title)
if handle:
win32gui.SetForegroundWindow(handle)
time.sleep(1)
(left,top,right,bottom)=win32gui.GetWindowRect(handle)
(leftPos,topPos)=(right-left)/2+left,top+200
win32api.SetCursorPos((leftPos,topPos))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0,0)
time.sleep(.5)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0,0)
time.sleep(.5)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0,0)