|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
不好意思,請問一些問題
Declare Function PostMessage Lib "user32" Alias"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParamAs Long, lParam As Any) As Long
Declare Function MapVirtualKey Lib "user32" Alias"MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) AsLong
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) AsLong
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
Private Sub Form_Load()
dim hwnd as long
hwnd = XXXXXX '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_keyup, vK_A,MakeKeyLparam(VK_A,WM_keyUP)'释放A键
End Sub
最後那三行 postmessage 怎麼如果用在 記事本 時,會入了三個 "a" 呢?
還有,怎樣鍵入 crtl + 某個鍵 呢? |
|