从 模仿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怎么用的更多相关文章

  1. C/C++使用keybd_event模拟键盘按键

    #include <stdio.h> #include <Windows.h> /* 设置键盘大小写状态 big:为TRUE则切换大写状态,否则切换小写状态 */ VOID M ...

  2. C#窗体模拟键盘按键(组合键)产生事件 ---- 通过keybd_event()函数

    如何模拟键盘按键触发产生的事件,比如模拟按下Alt + F4 关闭当前程序,Ctrl+Shift 切换输入法等 可以通过win32api 键盘事件 keybd_event() 来实现 1.定义键盘按键 ...

  3. C#窗体如何通过keybd_event()函数模拟键盘按键(组合键)产生事件

    如何模拟键盘按键触发产生的事件,比如模拟按下Alt + F4 关闭当前程序,Ctrl+Shift 切换输入法等 可以通过win32api 键盘事件 keybd_event() 来实现 1.定义键盘按键 ...

  4. UI自动化测试(四)AutoIT工具使用和robot对象模拟键盘按键操作

    AutoIT简介 AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作.它利用模拟键盘按键,鼠标移动和窗口/ ...

  5. golang实现模拟键盘按键

    公司前段时间要我写个小项目需要可以局域网内一个ipad控制另一台pc上的键盘输入,github上找了找,居然有个robotgo库这么神级的存在,感觉go的库真是越来越多了,虽然大部分都是第三方的.ht ...

  6. Delphi定时模拟键盘按键例程

    delphi模拟键盘按键实例delphi模拟键盘按键实例,只是模拟一个按键的例子而已.到一定时间按下模拟按下一个按键,delphi7编译通过. 10秒点击一下H键,其他键你们去找数值替换吧,网上大把的 ...

  7. Helium文档5-WebUI自动化-press模拟键盘按键输入技巧

    前言 press方法是用来模拟键盘按键输入,可以组合使用,来模拟键盘输入,解决一些难定位的元素 入参介绍 以下是press源码中的函数介绍 def press(key):  :入参 :param ke ...

  8. python 模拟按键模拟键盘按键按下放开

    python模拟按键 pip install pypiwin32安装库 import win32conimport win32apiimport time 导入 打个比方模拟A win32api.ke ...

  9. selenium学习-模拟键盘按键操作

    导入  from selenium.webdriver.common.keys import Keys  格式:Keys.XXX 一般这么用:send_keys(Keys.XXX) # coding= ...

随机推荐

  1. 【TLS】-TLS/SSL笔记

    目录 前言 概念 对称加密 非对称加密 公钥 单向加密 数字签名 基础 作用 SSL/TLS 模型 运作 问题&解答 基本过程 握手阶段 客户端发出请求(ClientHello) 服务器回应( ...

  2. 视频编码GOP

    GOP group of pictures GOP 指的就是两个I帧之间的间隔. 比较说GOP为120,如果是720 p60 的话,那就是2s一次I帧. 在视频编码序列中,主要有三种编码帧:I帧.P帧 ...

  3. Python import cStringIO ImportError: No module named 'cStringIO'

    From Python 3.0 changelog; The StringIO and cStringIO modules are gone. Instead, import the io modul ...

  4. 平分的直线 牛客网 程序员面试金典 C++ Python

    平分的直线 牛客网 程序员面试金典 C++ Python 题目描述 在二维平面上,有两个正方形,请找出一条直线,能够将这两个正方形对半分.假定正方形的上下两条边与x轴平行. 给定两个vecotrA和B ...

  5. Github图床设置

    创建新仓库 点击右上角加号->新建仓库,填写基本信息后点击下面的创建即可 https://github.com/new 创建新令牌 点击设置->开发者设置->私人令牌->生成新 ...

  6. Markdown使用方式

    区块 区块引用在段落开头使用>,后面紧跟一个空格符号 > 区块引用 > XXX > XXX 高级技巧 HTML元素 居中  <center>XXX</cent ...

  7. Delphi的手机程序隐藏顶部信号栏

    把TForm的BorderStyle设置为None 记之!

  8. Linux安装部署Zabbix

    Zabbix 是一个企业级的分布式开源监控方案,能够监控各种网络参数以及服务器健康性和完整性的软件.Zabbix使用灵活的通知机制,允许用户为几乎任何事件配置基于邮件的告警.这样可以快速反馈服务器的问 ...

  9. 记录自己的踩坑第一天 | CSS:vertical-align 属性

    前言 最近老师让大家单独写前后端分离项目,真是大家卷完后端,一起去卷前端了.(我以前都是主要负责后端,处于只大致看的懂的级别,说多了都是泪啊). 真是处于一边学一边写的状态,基本就是每天早上看上两~三 ...

  10. Spring Cloud Gateway实战之一:初探

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 关于<Spring Cloud Gateway实 ...