Python使用剪切板的方法
作者:Jackeriss 时间:2022-01-25 02:17:39
此段代码可以利用剪切板,完成自动复制粘贴等功能。(Windows)
import sys
import os.path
import win32clipboard as w
import win32con
import win32api
def getText():#读取剪切板
w.OpenClipboard()
d = w.GetClipboardData(win32con.CF_TEXT)
w.CloseClipboard()
return d
def setText(aString):#写入剪切板
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardData(win32con.CF_TEXT, aString)
w.CloseClipboard()
if __name__=='__main__':
a="你好"
setText(a)#将“你好”写入剪切板
#自动粘贴剪切板中的内容
win32api.keybd_event(17,0,0,0) #ctrl的键位码是17
win32api.keybd_event(86,0,0,0)#v的键位码是86
win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0)
win32api.keybd_event(13,0,0,0)#Enter的键位码是13
win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
标签:Python,剪切板
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决pip install psycopg2出错问题
2023-01-22 01:41:09
![](https://img.aspxhome.com/file/2023/5/80715_0s.jpg)
瞬间的快感之细节提升用户满意度
2010-11-17 19:19:00
![](https://img.aspxhome.com/file/UploadPic/201011/17/02-94s.jpg)
基于python实现百度翻译功能
2023-09-06 15:14:18
![](https://img.aspxhome.com/file/2023/3/70883_0s.jpg)
Python中list列表添加元素的3种方法总结
2022-10-03 21:40:43
关于shopex同步ucenter的redirect问题,导致script不运行
2023-07-13 05:20:53
用server.transfer隐藏网页真实地址
2007-12-04 13:02:00
![](https://img.aspxhome.com/file/UploadPic/up/2007120418262385.gif)
MySQL身份认证漏洞 升级到5.5.24可修正
2012-07-11 15:54:09
详解laravel安装使用Passport(Api认证)
2023-11-19 02:08:54
![](https://img.aspxhome.com/file/2023/9/89729_0s.png)
SQLServer中的切割字符串SplitString函数
2011-12-01 08:14:09
Python实现抖音热搜定时爬取功能
2022-01-03 03:48:29
![](https://img.aspxhome.com/file/2023/2/96962_0s.png)
Python调用scp向服务器上传文件示例
2023-12-09 18:56:34
python中subplot大小的设置步骤
2021-07-30 08:59:37
![](https://img.aspxhome.com/file/2023/2/67312_0s.png)
Python 读取位于包中的数据文件
2023-06-09 00:16:03
有效LOGO设计的最重要的提示
2010-06-09 12:05:00
![](https://img.aspxhome.com/file/UploadPic/20106/9/01-95s.gif)
MySQL字符集查看方法
2010-12-14 15:14:00
Python之基础函数案例详解
2023-07-09 19:43:24
![](https://img.aspxhome.com/file/2023/8/87808_0s.png)
Asp生成RSS的类_给网站加上RSS
2011-04-19 11:06:00
Python实现获取汉字偏旁部首的方法示例【测试可用】
2022-10-26 16:42:16
![](https://img.aspxhome.com/file/2023/5/76775_0s.png)
MySQL表设计优化与索引 (九)
2010-10-25 20:16:00
解决Tkinter中button按钮未按却主动执行command函数的问题
2023-05-04 18:38:08
![](https://img.aspxhome.com/file/2023/8/95798_0s.jpg)