脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python实现控制电脑鼠标和键盘,登录QQ的方法示例

python实现控制电脑鼠标和键盘,登录QQ的方法示例

2021-08-02 00:24shawn xie123 Python

这篇文章主要介绍了python实现控制电脑鼠标和键盘,登录QQ的方法,涉及Python基于Button,Controller,Key模块针对键盘、鼠标的控制相关操作技巧,需要的朋友可以参考下

本文实例讲述了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

延伸 · 阅读

精彩推荐