用 API 可以实现。但代码太多,这里无法上传,可以去下面链接下载
http://www.vbgood.com/viewthread.php?tid=74020
http://www.vbgood.com/viewthread.php?tid=57482
里面核心代码:
'*************************************************************************
'**函 数 名: EventKey
'**输 入: ByVal intKey(String) - Optional ByVal vntEspecially(Variant)
'**输 出: 无
'**功能描述: 模拟按键
'**全局变量:
'**调用模块:
'**作 者: Mr.David
'**日 期: 2007-06-23 11:45:53
'**修 改 人:
'**日 期:
'**版 本: V1.0.0
'*************************************************************************
Public Sub EventKey(ByVal intKey As Integer, Optional ByVal vntEspecially As Variant)
Dim lngEspecially As Long
If Not IsMissing(vntEspecially) Then
vntEspecially = LCase$(vntEspecially)
Select Case vntEspecially
Case "ctrl"
lngEspecially = VK_CONTROL
Case "alt"
lngEspecially = VK_MENU
Case "shift"
lngEspecially = VK_SHIFT
End Select
'模拟组合键
Call keybd_event(lngEspecially, MapVirtualKey(lngEspecially, 0), 0, 0)
Call keybd_event(intKey, MapVirtualKey(Asc(intKey), 0), 0, 0)
Call keybd_event(intKey, MapVirtualKey(Asc(intKey), 0), KEYEVENTF_KEYUP, 0)
Call keybd_event(lngEspecially, MapVirtualKey(lngEspecially, 0), KEYEVENTF_KEYUP, 0)
Else
'模拟按键
Call keybd_event(intKey, MapVirtualKey(intKey, 0), 0, 0)
Call keybd_event(intKey, MapVirtualKey(intKey, 0), KEYEVENTF_KEYUP, 0)
End If
End Sub