本文实例讲述了python实现控制电脑鼠标和键盘,登录QQ的方法。分享给大家供大家参考,具体如下:
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
|
import os from pynput.mouse import Button,Controller from pynput.keyboard import Key from pynput.keyboard import Controller as W from time import sleep mouse = Controller() keyboard = W() #点击右下角刷新桌面图标 mouse.position = ( 1433 , 884 ) mouse.press(Button.left) mouse.release(Button.left) sleep( 2 ) #打开QQ(跟进QQ具体路径来设置) os.startfile( "C:\Program Files (x86)\Tencent\QQ\Bin\QQScLauncher.exe" ) mouse = Controller() #读取鼠标位置 # sleep(5) # print('当前指针坐标位置是{}'.format(mouse.position)) sleep( 2 ) mouse.position = ( 654 , 340 ) mouse.press(Button.left) mouse.release(Button.left) sleep( 1 ) mouse.position = ( 729 , 489 ) keyboard.press(Key.tab) keyboard.release(Key.tab) keyboard.press(Key.tab) keyboard.release(Key.tab) keyboard.press(Key.tab) keyboard.release(Key.tab) keyboard.press(Key.tab) keyboard.release(Key.tab) keyboard.press(Key.tab) keyboard.release(Key.tab) keyboard.press(Key.tab) keyboard.release(Key.tab) #输入QQ账号 keyboard. type ( "QQ账号" ) sleep( 1 ) #输入密码 keyboard.press(Key.tab) keyboard.release(Key.tab) keyboard. type ( "QQ密码" ) #QQ密码指针坐标位置是(765, 551) keyboard.press(Key.enter) keyboard.release(Key.enter) |
希望本文所述对大家Python程序设计有所帮助。
原文链接:https://blog.csdn.net/xiezhiming1234/article/details/86483028