![]() | 马哥: 我想问一下DirectInput是不是只能监视键盘消息,而不能发送消息? 比如只能 If (diState.Key(DIK_9)) Then MsgBox "你按下了9" end if 而不会实现象keybd_event那种可以发送按下弹起的消息? keybd_event VK_9, 0, 0, 0 keybd_event VK_9, 0, KEYEVENTF_KEYUP, 0 如果可以实现发送消息,具体应该怎么写呢? |

这个我就不清楚了....
没玩过DX.......
看看SDK里有没有相关的东东吧.
不过论坛里有冰下海发的一篇模拟输入的帖子,不知道你看过没:
http://www.m5home.com/bbs/dispbbs.asp?boardid=27&Id=1283
没玩过DX.......
看看SDK里有没有相关的东东吧.
不过论坛里有冰下海发的一篇模拟输入的帖子,不知道你看过没:
http://www.m5home.com/bbs/dispbbs.asp?boardid=27&Id=1283
[codes=vb]Option Explicit
'*************************************************************************
'**模 块 名:ModSSendKeys
'**说 明:模拟按键(直接发按键消息到输入队列,与直接按键盘相等)
'**创 建 人:马大哈
'**日 期:2006年5月10日
'**描 述:网上收集,更改了部分代码.
'**备 注: 紫水晶工作室 版权所有
'** 更多模块/类模块请访问我站: http://www.m5home.com
'**版 本:V1.0
'*************************************************************************
Private Const VK_H = 72
Private Const VK_E = 69
Private Const VK_L = 76
Private Const VK_O = 79
Private Const KEYEVENTF_KEYUP = &H2
Private Const INPUT_MOUSE = 0
Private Const INPUT_KEYBOARD = 1
Private Const INPUT_HARDWARE = 2
Private Type MOUSEINPUT
dx As Long
dy As Long
mouseData As Long
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Private Type KEYBDINPUT
wVk As Integer
wScan As Integer
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Private Type HARDWAREINPUT
uMsg As Long
wParamL As Integer
wParamH As Integer
End Type
Private Type GENERALINPUT
dwType As Long
xi(0 To 23) As Byte
End Type
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Public Sub SendKey(ByVal bKey As KeyCodeConstants, ByVal PressORRelease As Long)
Dim GInput(0 To 1) As GENERALINPUT
Dim KInput As KEYBDINPUT
Dim I As Long
If PressORRelease = 0 Then
I = 0
Else
I = 1
End If
KInput.wVk = bKey 'the key we're going to press
KInput.dwFlags = 0 'press the key
'copy the structure into the input array's buffer.
GInput(0).dwType = INPUT_KEYBOARD ' keyboard input
CopyMemory GInput(0).xi(0), KInput, Len(KInput)
'do the same as above, but for releasing the key
KInput.wVk = bKey ' the key we're going to realease
KInput.dwFlags = KEYEVENTF_KEYUP ' release the key
GInput(1).dwType = INPUT_KEYBOARD ' keyboard input
CopyMemory GInput(1).xi(0), KInput, Len(KInput)
'send the input now
Call SendInput(1, GInput(I), Len(GInput(I)))
End Sub[/codes]
调用比较简单:
[codes=vb]Option Explicit
Private Sub Command1_Click()
Timer1.Interval = 2000 '两秒,足够切换到游戏画面了
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
SendKey vbKey1, 0
SendKey vbKey1, 1
SendKey vbKey2, 0
SendKey vbKey2, 1
SendKey vbKey3, 0
SendKey vbKey3, 1
SendKey vbKey4, 0
SendKey vbKey4, 1
SendKey vbKeyReturn, 0
SendKey vbKeyReturn, 1
End Sub[/codes]
以上代码可以成功登录QQ2009.