关于 keybd_event (vb篇)
最近有个VB的项目,做到64位的win7上,传统的VB6.0的sendkeys()函数没法用,可能是由于微软的证书验证机制造成的,于是最常用的一句话指令没法用了“SendKeys "{Home}+{End}"”(也就是全选当前的文本框字符)。
很自然的想到的API,轻松的改完:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long Private Const VK_ADD As Long = &H6B '加号键
Private Const VK_APPS As Long = &H5D 'Applications 键(相当于鼠标右键)
Private Const VK_BACK As Long = &H8 'BackSpace 键
Private Const VK_CAPITAL As Long = &H14 'Caps Lock 键(大小写转换键)
Private Const VK_CANCEL As Long = &H3 'Ctrl + Break 过程
Private Const VK_CONTROL As Long = &H11
Private Const VK_DECIMAL As Long = &H6E '小数点号键
Private Const VK_DELETE As Long = &H2E
Private Const VK_DIVIDE As Long = &H6F '除号键
Private Const VK_DOWN As Long = &H28
Private Const VK_END As Long = &H23
Private Const VK_ESCAPE As Long = &H1B
Private Const VK_F1 As Long = &H70
Private Const VK_F10 As Long = &H79
Private Const VK_F11 As Long = &H7A
Private Const VK_F12 As Long = &H7B
Private Const VK_F2 As Long = &H71
Private Const VK_F3 As Long = &H72
Private Const VK_F4 As Long = &H73
Private Const VK_F5 As Long = &H74
Private Const VK_F6 As Long = &H75
Private Const VK_F7 As Long = &H76
Private Const VK_F8 As Long = &H77
Private Const VK_F9 As Long = &H78
Private Const VK_HOME As Long = &H24
Private Const VK_INSERT As Long = &H2D
Private Const VK_LCONTROL As Long = &HA2
Private Const VK_LEFT As Long = &H25
Private Const VK_LMENU As Long = &HA4 '左 Alt 键
Private Const VK_LSHIFT As Long = &HA0
Private Const VK_LWIN As Long = &H5B
Private Const VK_MENU As Long = &H12 'Alt 键
Private Const VK_MULTIPLY As Long = &H6A '乘号键
Private Const VK_NEXT As Long = &H22 '下翻页键
Private Const VK_NUMLOCK As Long = &H90
Private Const VK_NUMPAD0 As Long = &H60
Private Const VK_NUMPAD1 As Long = &H61
Private Const VK_NUMPAD2 As Long = &H62
Private Const VK_NUMPAD3 As Long = &H63
Private Const VK_NUMPAD4 As Long = &H64
Private Const VK_NUMPAD5 As Long = &H65
Private Const VK_NUMPAD6 As Long = &H66
Private Const VK_NUMPAD7 As Long = &H67
Private Const VK_NUMPAD8 As Long = &H68
Private Const VK_NUMPAD9 As Long = &H69
Private Const VK_PAUSE As Long = &H13
Private Const VK_PRINT As Long = &H2A
Private Const VK_PRIOR As Long = &H21 '上翻页键
Private Const VK_RCONTROL As Long = &HA3
Private Const VK_RETURN As Long = &HD '回车键
Private Const VK_RIGHT As Long = &H27
Private Const VK_RMENU As Long = &HA5 '右 Alt 键
Private Const VK_RSHIFT As Long = &HA1
Private Const VK_RWIN As Long = &H5C
Private Const VK_SCROLL As Long = &H91 'Scroll Lock 键
Private Const VK_SEPARATOR As Long = &H6C '小键盘上的回车键
Private Const VK_SHIFT As Long = &H10
Private Const VK_SLEEP As Long = &H5F '休眠键
Private Const VK_SNAPSHOT As Long = &H2C 'Print Screen 键
Private Const VK_SPACE As Long = &H20
Private Const VK_SUBTRACT As Long = &H6D '减号键
Private Const VK_TAB As Long = &H9
Private Const VK_UP As Long = &H26
Private Const VK_OEM_1 As Long = &HBA 'Windows 2000:对于 US 标准键盘,是“;:”键
Private Const VK_OEM_2 As Long = &HBF 'Windows 2000:对于 US 标准键盘,是“/?”键
Private Const VK_OEM_3 As Long = &HC0 'Windows 2000:对于 US 标准键盘,是“`~”键
Private Const VK_OEM_4 As Long = &HDB 'Windows 2000:对于 US 标准键盘,是“[{”键
Private Const VK_OEM_5 As Long = &HDC 'Windows 2000:对于 US 标准键盘,是“\|”键
Private Const VK_OEM_6 As Long = &HDD 'Windows 2000:对于 US 标准键盘,是“]}”键
Private Const VK_OEM_7 As Long = &HDE 'Windows 2000:对于 US 标准键盘,是“单/双引号”键
Private Const VK_OEM_COMMA As Long = &HBC 'Windows 2000:对于任何国家/地区,是“,”键
Private Const VK_OEM_MINUS As Long = &HBD 'Windows 2000:对于任何国家/地区,是“-”键
Private Const VK_OEM_PERIOD As Long = &HBE 'Windows 2000:对于任何国家/地区,是“.”键
Private Const VK_OEM_PLUS As Long = &HBB 'Windows 2000:对于任何国家/地区,是“+”键 Private Const KEYEVENTF_KEYUP = &H2
Public Sub SendKeysAPI_HOME_END(frmCur As String)
'下面是发送 组合 键码:
Call keybd_event(VK_HOME, 0, 0, )
Call keybd_event(VK_LSHIFT,0, , )
Call keybd_event(VK_END, 0,, )
Call keybd_event(VK_END, 0, KEYEVENTF_EXTENDEDKEY, )
Call keybd_event(VK_LSHIFT, 0,KEYEVENTF_EXTENDEDKEY , )
Call keybd_event(VK_HOME, 0, KEYEVENTF_EXTENDEDKEY , )
End Sub
可是测试的时候很多问题,这个函数很简单,网上大家都这么用,为什么我这不行呢,现象是有时没反应,有时shift按下不放,无奈啊,抱着无解的心态打开MSDN,看了下函数说明,才知道用的有问题,修改如下:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long Private Const VK_ADD As Long = &H6B '加号键
Private Const VK_APPS As Long = &H5D 'Applications 键(相当于鼠标右键)
Private Const VK_BACK As Long = &H8 'BackSpace 键
Private Const VK_CAPITAL As Long = &H14 'Caps Lock 键(大小写转换键)
Private Const VK_CANCEL As Long = &H3 'Ctrl + Break 过程
Private Const VK_CONTROL As Long = &H11
Private Const VK_DECIMAL As Long = &H6E '小数点号键
Private Const VK_DELETE As Long = &H2E
Private Const VK_DIVIDE As Long = &H6F '除号键
Private Const VK_DOWN As Long = &H28
Private Const VK_END As Long = &H23
Private Const VK_ESCAPE As Long = &H1B
Private Const VK_F1 As Long = &H70
Private Const VK_F10 As Long = &H79
Private Const VK_F11 As Long = &H7A
Private Const VK_F12 As Long = &H7B
Private Const VK_F2 As Long = &H71
Private Const VK_F3 As Long = &H72
Private Const VK_F4 As Long = &H73
Private Const VK_F5 As Long = &H74
Private Const VK_F6 As Long = &H75
Private Const VK_F7 As Long = &H76
Private Const VK_F8 As Long = &H77
Private Const VK_F9 As Long = &H78
Private Const VK_HOME As Long = &H24
Private Const VK_INSERT As Long = &H2D
Private Const VK_LCONTROL As Long = &HA2
Private Const VK_LEFT As Long = &H25
Private Const VK_LMENU As Long = &HA4 '左 Alt 键
Private Const VK_LSHIFT As Long = &HA0
Private Const VK_LWIN As Long = &H5B
Private Const VK_MENU As Long = &H12 'Alt 键
Private Const VK_MULTIPLY As Long = &H6A '乘号键
Private Const VK_NEXT As Long = &H22 '下翻页键
Private Const VK_NUMLOCK As Long = &H90
Private Const VK_NUMPAD0 As Long = &H60
Private Const VK_NUMPAD1 As Long = &H61
Private Const VK_NUMPAD2 As Long = &H62
Private Const VK_NUMPAD3 As Long = &H63
Private Const VK_NUMPAD4 As Long = &H64
Private Const VK_NUMPAD5 As Long = &H65
Private Const VK_NUMPAD6 As Long = &H66
Private Const VK_NUMPAD7 As Long = &H67
Private Const VK_NUMPAD8 As Long = &H68
Private Const VK_NUMPAD9 As Long = &H69
Private Const VK_PAUSE As Long = &H13
Private Const VK_PRINT As Long = &H2A
Private Const VK_PRIOR As Long = &H21 '上翻页键
Private Const VK_RCONTROL As Long = &HA3
Private Const VK_RETURN As Long = &HD '回车键
Private Const VK_RIGHT As Long = &H27
Private Const VK_RMENU As Long = &HA5 '右 Alt 键
Private Const VK_RSHIFT As Long = &HA1
Private Const VK_RWIN As Long = &H5C
Private Const VK_SCROLL As Long = &H91 'Scroll Lock 键
Private Const VK_SEPARATOR As Long = &H6C '小键盘上的回车键
Private Const VK_SHIFT As Long = &H10
Private Const VK_SLEEP As Long = &H5F '休眠键
Private Const VK_SNAPSHOT As Long = &H2C 'Print Screen 键
Private Const VK_SPACE As Long = &H20
Private Const VK_SUBTRACT As Long = &H6D '减号键
Private Const VK_TAB As Long = &H9
Private Const VK_UP As Long = &H26
Private Const VK_OEM_1 As Long = &HBA 'Windows 2000:对于 US 标准键盘,是“;:”键
Private Const VK_OEM_2 As Long = &HBF 'Windows 2000:对于 US 标准键盘,是“/?”键
Private Const VK_OEM_3 As Long = &HC0 'Windows 2000:对于 US 标准键盘,是“`~”键
Private Const VK_OEM_4 As Long = &HDB 'Windows 2000:对于 US 标准键盘,是“[{”键
Private Const VK_OEM_5 As Long = &HDC 'Windows 2000:对于 US 标准键盘,是“\|”键
Private Const VK_OEM_6 As Long = &HDD 'Windows 2000:对于 US 标准键盘,是“]}”键
Private Const VK_OEM_7 As Long = &HDE 'Windows 2000:对于 US 标准键盘,是“单/双引号”键
Private Const VK_OEM_COMMA As Long = &HBC 'Windows 2000:对于任何国家/地区,是“,”键
Private Const VK_OEM_MINUS As Long = &HBD 'Windows 2000:对于任何国家/地区,是“-”键
Private Const VK_OEM_PERIOD As Long = &HBE 'Windows 2000:对于任何国家/地区,是“.”键
Private Const VK_OEM_PLUS As Long = &HBB 'Windows 2000:对于任何国家/地区,是“+”键 Private Const KEYEVENTF_KEYUP = &H2
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Public Sub SendKeysAPI_HOME_END(frmCur As String)
'下面是发送 组合 键码:
Call keybd_event(VK_HOME, MapVirtualKey(VK_HOME, ), KEYEVENTF_EXTENDEDKEY Or , )
Call keybd_event(VK_LSHIFT, MapVirtualKey(VK_SHIFT, ), KEYEVENTF_EXTENDEDKEY Or , )
Call keybd_event(VK_END, MapVirtualKey(VK_END, ), KEYEVENTF_EXTENDEDKEY Or , )
Call keybd_event(VK_END, MapVirtualKey(VK_END, ), KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, )
Call keybd_event(VK_LSHIFT, MapVirtualKey(VK_LSHIFT, ), KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, )
Call keybd_event(VK_HOME, MapVirtualKey(VK_HOME, ), KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, )
End Sub
也就是与上KEYEVENTF_EXTENDEDKEY(扩展键)的标识就行了,至于原因,我猜某些特殊键,例如shift等得加吧。
关于 keybd_event (vb篇)的更多相关文章
- TGL站长关于常见问题的回复
问题地址: http://www.thegrouplet.com/thread-112923-1-1.html 问题: 网站配有太多的模板是否影响网站加载速度 月光答复: wp不需要删除其他的模板,不 ...
- 使用swoole进行消息推送通知,配合vb.net进行客户端开发一样爽[开发篇]
在以前的项目中,就曾听说过swoole的大名,想用来进行消息推送,但是当时只是有了初步的了解,并不敢大胆的运用到线上产品.所谓 识不足则多虑,威不足则多怒.所以就是怕,只能跟领导说了运用极光的推送功能 ...
- VB查询数据库之终极篇——机房收费系统总结(七)
机房收费系统总结系列到此就算是要结束了.在做机房收费系统之前,做了学生管理系统,可以说,对机房收费系统的帮助很大. 在机房收费系统中,数据库的查询,数据写入数据库,更改数据库内的信息等一些操作在学生信 ...
- VB.NET视频总结——基础篇
VB.NET视频是台湾讲师曹祖胜和林煌章共同带来的经典视频,视频中老师的台湾腔特别重,听起来有些别扭.而且对于计算机方面的术语翻译的与大陆有很大差异,所以刚开始看视频的时候总是进入不了状态,一头雾水的 ...
- 第一篇随笔:用VB.NET搞点简单事情(1)
网络上能搜索到的爬虫文章大多是用python做的,也有少部分是C#做的(小声:所以用VB.NET也可以做爬虫.本文写的是第一步:获取网页) 使用代码前先imports以下内容 Imports Syst ...
- VB.NET TextBox 只允许输入1-100之间的整数 简洁篇
Dim Str As String = "" Private Sub txtRecond_KeyUp(sender As System.Object, e As System.Wi ...
- 三层登录实例VB.NET版详解---理论加实战篇
层,百度百科这样解释,首先-重叠起来的东西:重叠起来的东西中的一部分:层次|表层|大气层.其次-重叠:重复:层峦叠嶂|层出不穷.最后-量词,用于可以分出层次的事物,女孩儿强烈的第六感,三层中的层一定是 ...
- 三层登录实例VB.NET版具体解释---理论加实战篇
层,百度百科这样解释,首先-重叠起来的东西:重叠起来的东西中的一部分:层次|表层|大气层.其次-重叠.反复:层峦叠嶂|层出不穷.最后-量词,用于能够分出层次的事物.女孩儿强烈的第六感,三层中的层一定是 ...
- 论:开发者信仰之“天下IT是一家“(Java .NET篇)
比尔盖茨公认的IT界领军人物,打造了辉煌一时的PC时代. 2008年,史蒂夫鲍尔默接替了盖茨的工作,成为微软公司的总裁. 2013年他与微软做了最后的道别. 2013年以后,我才真正看到了微软的变化. ...
随机推荐
- Linux 4.1内核编译报告
编译环境 Arch Linux on VirtualBox 下载内核 https://www.kernel.org/ 下载的内核压缩包,此时的最新内核版本为4.1: 解压包 # tar -xvJf l ...
- css实现鼠标移入table时出现滚动条且table内容不移位
一般是这样: 表格的标题和内容分别由一个table组成,其中表格内容的table由一个class="table-body"的div包裹.css如下 .tContainer .tab ...
- Chrome 中的 JavaScript 断点设置和调试技巧 (转载)
原文地址:http://han.guokai.blog.163.com/blog/static/136718271201321402514114/ 你是怎么调试 JavaScript 程序的?最原始的 ...
- ECharts 是一款开源
ECharts
- php转化输入日期为Unix 纪元到当前时间的秒数 日期筛选
多条件筛选时 日期筛选 部分 demo http://pan.baidu.com/s/1hqGF5Ik 时间输入控件http://www.jq22.com/jquery-info332 输入控件 ...
- win7 IIS7.0 【IIS 管理器无法验证此内置帐户是否有访问权】
异常信息: 服务器配置为将传递身份验证和内置帐户一起使用,以访问指定的物理路径.但是,IIS 管理器无法验证此内置帐户是否有访问权.请确保应用程序池标识具有该物理路径的读取访问权.如果此服务器加入到域 ...
- bzoj2067: [Poi2004]SZN
Description String-Toys joint-stock 公司需要你帮他们解决一个问题. 他们想制造一个没有环的连通图模型. 每个图都是由一些顶点和特定数量的边构成. 每个顶点都可以连向 ...
- Microsoft Detours 2.1简介
http://blog.163.com/qcb_163/blog/static/9545466420117851038971/ Microsoft Detours 2.1简介 2011-08-0817 ...
- kibaba 选择字段
- 【HDOJ】4983 Goffi and GCD
题意说的非常清楚,即求满足gcd(n-a, n)*gcd(n-b, n) = n^k的(a, b)的不同对数.显然gcd(n-a, n)<=n, gcd(n-b, n)<=n.因此当n不为 ...