VB 发送模拟按键
Dim ReturnValue, I
ReturnValue = Shell("Calc.EXE", 1) ' 运行计算器。
AppActivate ReturnValue ' 激活计算器。
For I = 1 To 100 ' 设置计数循环。
SendKeys I & "{+}", True ' 按下按键给计算器
Next I ' 将所有 I 值相加。
SendKeys "=", True ' 取得总合。
SendKeys "%{F4}", True ' 按 ALT+F4 关闭计算器 http://zhidao.baidu.com/question/33428479.html
窗体代码:
前提你得得到你游戏的句柄 hwnd = &H307F8 '把个307f8改为你游戏的句柄就可以了 Spy.exe这个软件可以抓句柄
Private Sub Form_Load()
Dim hwnd As Long
hwnd = &H307F8 'XXXXX表示记事本编辑框的句柄
PostMessage hwnd, WM_KEYDOWN, VK_A, MakeKeyLparam(VK_A, WM_KEYDOWN) '按下A键
PostMessage hwnd, WM_CHAR, Asc("A"), MakeKeyLparam(VK_A, WM_KEYDOWN) '输入字符A
PostMessage hwnd, WM_UP, VK_A, MakeKeyLparam(VK_A, WM_UP) '释放A键
End Sub
模块代码:
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_CHAR = &H102
Public Const VK_A = &H41
Function MakeKeyLparam(ByVal VirtualKey As Long, ByVal flag As Long) As Long
Dim s As String
Dim Firstbyte As String 'lparam参数的24-31位
If flag = WM_KEYDOWN Then '如果是按下键
Firstbyte = "00"
Else
Firstbyte = "C0" '如果是释放键
End If
Dim Scancode As Long
'获得键的扫描码
Scancode = MapVirtualKey(VirtualKey, 0)
Dim Secondbyte As String 'lparam参数的16-23位,即虚拟键扫描码
Secondbyte = Right("00" & Hex(Scancode), 2)
s = Firstbyte & Secondbyte & "0001" '0001为lparam参数的0-15位,即发送次数和其它扩展信息
MakeKeyLparam = Val("&H" & s)
End Function
按键 代码
SHIFT +
CTRL ^
相关文档:
http://hi.baidu.com/qwestw/blog/item/a8b41663eb7fca690d33fa46.html
能记录到中文,缺点是不能记录到Ctrl,shift,alt,capslock,home,del,pageUP,pageDown等件的按下状态。
vb6代码如下:
Private Sub Form_Load()
WM_HXWDLLWX_HOOKKEY = RegisterWindowMessage("WM_HXWDLLWX_HOOKKEY")
PrevWndProc = SetWind ......
'创建快捷方式,兼容vista
'要把vb6stkit.DLL放到程序目录
'敖士伟 09-10-27
'只对“桌面”和“开启”有效,其它还没做
'=========开启外部同步程序定义开始
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFF 'Wait forever
Const WAIT_OBJECT_0 = 0 'The state of the spe ......
Private Sub Command1_Click()
Dim dso As New XMLDSOControl
Dim doc As IXMLDOMDocument
Set doc = dso.XMLDocument
Dim rel As IXMLDOMNodeList
Set x = CreateObject("Microsoft.XMLHTTP")
x.Open "GET", "http://127.0.0.1:8080/emrb/Mrbmodel?action=dis&u ......
Option Explicit
Private Type UNICODE_STRING
Length As Integer
MaximumLength As Integer
Buffer As Long
End Type
Private Type OBJECT_ATTRIBUTES
Length As Long
RootDirectory As Long
  ......