keybd_event模拟键盘按键,mouse_event怎么用
从 模仿UP主,用Python实现一个弹幕控制的直播间! - 蛮三刀酱 - 博客园 (cnblogs.com) 知道了 PyAutoGUI:
* Moving the mouse and clicking in the windows of other applications.
* Sending keystrokes to applications (for example, to fill out forms).
* Take screenshots, and given an image (for example, of a button or checkbox), and find it on the screen.
* Locate an application's window, and move, resize, maximize, minimize, or close it (Windows-only, currently).
* Display alert and message boxes.
Much of this code is based on information gathered from Paul Barton's PyKeyboard in PyUserInput from 2013, itself derived from Akkana Peck's pykey in 2008 ( http://www.shallowsky.com/software/crikey/pykey-0.1 ), itself derived from her "Crikey" lib. 久经考验喽,Windows, Linux, OS X都支持唷。
看它的源码可知道keybd_event的用法,例如:
def _keyDown(key):
"""Performs a keyboard key press without the release. This will put that
key in a held down state. NOTE: For some reason, this does not seem to cause key repeats like would
happen if a keyboard key was held down on a text field. Args:
key (str): The key to be pressed down. The valid names are listed in
pyautogui.KEY_NAMES. Returns:
None
"""
if key not in keyboardMapping or keyboardMapping[key] is None:
return needsShift = pyautogui.isShiftCharacter(key) """
# OLD CODE: The new code relies on having all keys be loaded in keyboardMapping from the start.
if key in keyboardMapping.keys():
vkCode = keyboardMapping[key]
elif len(key) == 1:
# note: I could use this case to update keyboardMapping to cache the VkKeyScan results, but I've decided not to just to make any possible bugs easier to reproduce.
vkCode = ctypes.windll.user32.VkKeyScanW(ctypes.wintypes.WCHAR(key))
if vkCode == -1:
raise ValueError('There is no VK code for key "%s"' % (key))
if vkCode > 0x100: # the vk code will be > 0x100 if it needs shift
vkCode -= 0x100
needsShift = True
"""
mods, vkCode = divmod(keyboardMapping[key], 0x100) for apply_mod, vk_mod in [(mods & 4, 0x12), (mods & 2, 0x11),
(mods & 1 or needsShift, 0x10)]: #HANKAKU not supported! mods & 8
if apply_mod:
ctypes.windll.user32.keybd_event(vk_mod, 0, KEYEVENTF_KEYDOWN, 0) #
ctypes.windll.user32.keybd_event(vkCode, 0, KEYEVENTF_KEYDOWN, 0)
for apply_mod, vk_mod in [(mods & 1 or needsShift, 0x10), (mods & 2, 0x11),
(mods & 4, 0x12)]: #HANKAKU not supported! mods & 8
if apply_mod:
ctypes.windll.user32.keybd_event(vk_mod, 0, KEYEVENTF_KEYUP, 0) #
虽然它是python写的,但对VC和C#程序员很有参考价值。我是做了个半拉子不大好使。
我从github下载了源码放在博客园里了:https://files.cnblogs.com/files/blogs/714801/pyautogui-master.zip
pyautogui\_pyautogui_win.py
ctypes - A foreign function library for Python
>>> from ctypes import *
>>> print(windll.kernel32)
<WinDLL 'kernel32', handle ... at ...>
pyautogui的作者们:
Abhijeet Singh https://github.com/cseas
Al Sweigart https://github.com/asweigart/
Alexandr Orlov https://github.com/hey-sancho
alphaCTzo7G https://github.com/alphaCTzo7G
Andrew Selzer https://github.com/afs2015
Andy Dam https://github.com/andydam
Anwar A. Ruff https://github.com/aaruff
Ari Lacenski https://github.com/tensory
Ashok Fernandez https://github.com/ashokfernandez/
Brian Redmond https://github.com/bredmond
Christopher Valles https://github.com/christophervalles
clach04 https://github.com/clach04
Clayton A. Alves https://github.com/claytonaalves
cryzed https://github.com/cryzed
Daniel D. Beck https://github.com/ddbeck
danielboone https://github.com/danielboone
Davee Nguyen https://github.com/daveenguyen
David Siah https://github.com/dsiah
Denilson Figueiredo de Sá https://github.com/denilsonsa
Dominik Schmelz https://github.com/DIDoS
dragon778 https://github.com/dragon788
Duxxi https://github.com/sjhhh3
Eric https://github.com/bleuetnoir
ErtugrulSener https://github.com/ErtugrulSener
Fornost461 https://github.com/Fornost461
Harrison https://github.com/Sentdex
Hugo Salvador https://github.com/hugoesb
i-need-to-tell-you-something https://github.com/i-need-to-tell-you-something
jakibaki https://github.com/
Jeff Triplett https://github.com/jefftriplett
Jeremy R. Gray https://github.com/jeremygray
Jeromie Kirchoff https://github.com/JayRizzo
Joel Gomes da Silva https://github.com/joelgomes1994
johnborgmann https://github.com/johnborgmann
Jon Winsley https://github.com/glitchassassin
jorg-j https://github.com/jorg-j
Jose Riha https://github.com/jose1711
Julien Schueller https://github.com/jschueller
Korons https://github.com/Korons
lb1a https://github.com/lb1a
Lesmana Zimmer https://github.com/lesmana
liberme https://github.com/liberme
Matt Olsen https://github.com/digwanderlust
mvbentes https://github.com/mvbentes
nexcvon https://github.com/nexcvon
Oleg Höfling https://github.com/hoefling
optroot https://github.com/optroot
pgkos https://github.com/pgkos
qiujieqiong https://github.com/qiujieqiong
Ricardo Amendoeira https://github.com/ric2b
Scott Noyes https://github.com/snoyes
Sergio Encarnación https://github.com/Sergioenc28
sneakypete81 https://github.com/sneakypete81
Stefan Hoelzl https://github.com/stefanhoelzl
Stephen Ellis https://github.com/saellis
Steven Shave https://github.com/stevenshave
Tim Gates https://github.com/timgates42
Timothy Crory https://github.com/tcrory
undefx https://github.com/undefx
Vélmer Oliveira https://github.com/velmer
Yoshiaki Ono https://github.com/fx-kirin
Stefan Hoelzl https://github.com/stefanhoelzl
keybd_event模拟键盘按键,mouse_event怎么用的更多相关文章
- C/C++使用keybd_event模拟键盘按键
#include <stdio.h> #include <Windows.h> /* 设置键盘大小写状态 big:为TRUE则切换大写状态,否则切换小写状态 */ VOID M ...
- C#窗体模拟键盘按键(组合键)产生事件 ---- 通过keybd_event()函数
如何模拟键盘按键触发产生的事件,比如模拟按下Alt + F4 关闭当前程序,Ctrl+Shift 切换输入法等 可以通过win32api 键盘事件 keybd_event() 来实现 1.定义键盘按键 ...
- C#窗体如何通过keybd_event()函数模拟键盘按键(组合键)产生事件
如何模拟键盘按键触发产生的事件,比如模拟按下Alt + F4 关闭当前程序,Ctrl+Shift 切换输入法等 可以通过win32api 键盘事件 keybd_event() 来实现 1.定义键盘按键 ...
- UI自动化测试(四)AutoIT工具使用和robot对象模拟键盘按键操作
AutoIT简介 AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作.它利用模拟键盘按键,鼠标移动和窗口/ ...
- golang实现模拟键盘按键
公司前段时间要我写个小项目需要可以局域网内一个ipad控制另一台pc上的键盘输入,github上找了找,居然有个robotgo库这么神级的存在,感觉go的库真是越来越多了,虽然大部分都是第三方的.ht ...
- Delphi定时模拟键盘按键例程
delphi模拟键盘按键实例delphi模拟键盘按键实例,只是模拟一个按键的例子而已.到一定时间按下模拟按下一个按键,delphi7编译通过. 10秒点击一下H键,其他键你们去找数值替换吧,网上大把的 ...
- Helium文档5-WebUI自动化-press模拟键盘按键输入技巧
前言 press方法是用来模拟键盘按键输入,可以组合使用,来模拟键盘输入,解决一些难定位的元素 入参介绍 以下是press源码中的函数介绍 def press(key): :入参 :param ke ...
- python 模拟按键模拟键盘按键按下放开
python模拟按键 pip install pypiwin32安装库 import win32conimport win32apiimport time 导入 打个比方模拟A win32api.ke ...
- selenium学习-模拟键盘按键操作
导入 from selenium.webdriver.common.keys import Keys 格式:Keys.XXX 一般这么用:send_keys(Keys.XXX) # coding= ...
随机推荐
- python write() argument must be str, not bytes
python pickle from __future__ import absolute_import from __future__ import division from __future__ ...
- 挂载nfs存储
查看nfs服务器上提供了哪些nfs目录 showmount -e 172.16.3.8 使用showmount前需要安装nfs-utils包 yum install nfs-utils -y 挂载nf ...
- windows 系统文件夹挂载到 Linux 系统,拷贝(发送)文件到 windows 系统,实现异地备份
1.在windows 系统上配置好共享文件夹,用来接收Linux 系统的文件 注意:关闭windows 系统防火墙,或者添加进出站规则 2.在Linux 系统中,创建需要拷贝的文件目录 #mkdi ...
- Laravel/Lumen 分组求和问题 where groupBy sum
在Laravel中使用分组求和,如果直接使用Laravel各数据库操作方法,应该会得出来如下代码式: DB::table('table_a') ->where('a','=',1) ->g ...
- java 三大特性_继承、封装、多态_day005
一.继承: java的三大特性之一.两个类之间通过extends关键字来描述父子关系,子类便可拥有父类的公共方法和公共属性.子类可以继承父类的方法和属性,子类也可以自己定义没有的方法或者通过覆盖父类的 ...
- 攻防世界 Misc 新手练习区 如来十三掌 Writeup
攻防世界 Misc 新手练习区 如来十三掌 Writeup 题目介绍 题目考点 佛曰加密.base64.Rot13等加密方法的了解 Writeup 下载并打开附件 联想到佛曰加密,复制内容到 佛曰加密 ...
- ASP.NET Core设置URLs的几种方法
前言 在使用ASP.NET Core 3.1开发时,需要配置服务器监听的端口和协议,官方帮助文档进行简单说明,文档中提到了4种指定URL的方法 设置ASPNETCORE_URLS 环境变量: 使用do ...
- 大一C语言学习笔记(3)---对于程序员来说,学历和能力,到底哪个重要?
在高考失利后,我合理地萎靡一段时间,振作起来之后选择了我憧憬了10年的计算机专业---软件工程.但由于分数受限,也是选择了二本普通院校黑科技(我当然爱她,我的母校),而因为学历上的自卑,让我有了想考研 ...
- windows 上搭建 sftp 服务器 -freesshd全过程( 在linux上部署逐浪CMS的必读教程)
文章标题: windows 上搭建 sftp 服务器 - freesshd全过程 关键字 : freesshd 文章分类: 教程 创建时间: 2020年3月23日 缘由 动手 第一步:添加用户 第二步 ...
- Sentry 官方 JavaScript SDK 简介与调试指南
系列 1 分钟快速使用 Docker 上手最新版 Sentry-CLI - 创建版本 快速使用 Docker 上手 Sentry-CLI - 30 秒上手 Source Maps Sentry For ...