win32api 中mouse_event、GetFullPathName(fileName)、.GetLocalTime()、GetSystemDirectory()等函数的用法

时间:2021-03-30 13:18:33   收藏:0   阅读:0

关注公众号:【小张Python】,为你准备了 50+ 本Python 精品电子书籍 与 50G + 优质视频学习资料,后台回复关键字:1024 即可获取;如果对博文内容有什么疑问,公众号后台添加作者【个人微信】,可与作者直接进行交流

win32api.GetFullPathName(fileName)

返回文件名的完整路径,即绝对路径;

>>> import win32api
>>> print(win32api.GetFullPathName(‘ceshi.txt‘)
G:\Coding\Blog_Coding\PyWin32\ceshi.txt

win32api.GetLocalTime()

返回当前本地时间

>>> print(win32api.GetLocalTime())
(2021, 3, 0, 28, 12, 11, 55, 235)

win32api.GetSystemDirectory()

返回存放Windows系统文件夹

>>> print(win32api.GetSystemDirectory())
C:\Windows\system32

win32api.GetVersion()

返回 Windows 版本信息,返回信息中左边表示 windows 主要/次要版本,右边表示 windows Nt、windows7,windows8 等版本信息;

>>> print(win32api.GetVersion())
1247870986

win32api.mouse_event(dwFlags,dx,dy,dwData)

利用该参数可以模拟鼠标进行一些操作,例如鼠标向右或向下移动一定位置后按下、移动滑轮等操作;

关于 DWORD 参数设定,需参考 Windows 官方函数 API ,里面有详细说明,连接如下 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event

技术图片

用法举例,下面代码中表示鼠标向右移动 32、向下移动 40 ,然后按下左键

>>> win32api.mouse_event(0x0002,32,40,0)

这类函数相对还是比较有用,通过它可以实现一些自动化操作

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!