python remote control computer

python has a large number of third-party libraries, and simple grammar. Today, Yang will remote control the computer with python

The so-called, before making any decisions, before implementing any demand, we need to analyze, stroked a clear idea of ​​remote control computer, nothing more than to receive remote commands and commands to perform the corresponding operation according to. That Here, we use micro-channel to receive commands, use of our library itchat a remote control computer

Press said, we have to complete the requirements, the task is simply broken down, first of all, a message is received command, and then execute the corresponding operation according to the corresponding instructions, which we need to consider a problem is inadvertently problem.

python there are plenty of third-party libraries, where we use the third-party libraries itchat

First through third-party libraries to install pip

​ pip install itchat

Third-party libraries

​ import itchat

Start code, just-do, first to a standard routine:

main DEF ():
Pass
IF __name__ __ == '__ main__':
main ()
. 1
2
. 3
. 4
so that the micro-channel runs

itchat Import
DEF main ():
# Log scan code micro-channel heat load to avoid duplication
itchat.auto_login (hotReload = True)
# micro channel running
itchat.run ()
IF __name__ __ == '__ main__':
main ()
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
receives the micro-channel message, an instruction to obtain, operation

OS Import
@ itchat.msg_register ( 'the Text')
DEF main (MSG):
Message MSG = [ 'the Text']
IF Message == 'off':
the os.system ( 'the shutdown / S / T 0')
. 1
2
. 3
. 4
5
6
probably already thinking that, then we should do more optimized, such as inadvertently solve other issues

The complete code is as follows:

itchat Import
Import OS
Import CV2
@ itchat.msg_register ( 'the Text')
DEF main (MSG):
. MSG Message = [ 'the Text'] Strip ()
ToUserName MSG = [ 'ToUserName']
fromusername MSG = [ 'fromusername']
IF == ToUserName fromusername:
Tip = 'turn on control input is off by default'
itchat.send (Tip, 'filehelper')
IF ToUserName == 'filehelper':
Control (Message)
in Flag = False
DEF Control (Message):
Global in Flag
the Message == IF 'ON':
Tip = 'now you can start or shutdown control input input pictures'
itchat.send (Tip,' filehelper ')
Flag = True
IF the Message ==' OFF ':
Tip =' has now been manipulated open the control input on '
itchat.send(tip,'filehelper')
flag = False
if flag == True:
if message == '关机':
cmd()
elif message == '拍照':
img()
def cmd(http://www.my516.com):
os.system('shutdown /s /t 0')
def img():
cap = cv2.VideoCapture(0)
ret ,img = cap.read()
filename = 'wechat.jpg'
cv2.imwrite(filename,img)
cap.release()
itchat.send_image(filename,'filehelper')
def main():
itchat.auto_login(hotReload=True)
itchat.run()
if __name__=='__main__':
main()
--------------------- 

Guess you like

Origin www.cnblogs.com/hyhy904/p/10995882.html