需要一个vb编写的驱动级键盘模拟代码 100
只需要模拟3个键TYU先按T间隔0.5秒按Y间隔0.5秒按U间隔1秒在按T。。。。周而复始按F11开始F12停止(键盘PS2)在下新手,请标明代码解释,按钮代码分清楚,要...
只需要模拟3个键 T Y U 先按T 间隔0.5秒 按Y 间隔0.5秒 按U 间隔1秒在按T 。。。。周而复始 按F11开始 F12停止 (键盘PS2)在下新手,请标明代码解释,按钮代码分清楚,要不然我不知道代码都写在哪里。
经典的话还加分!!!!!!!!!
tpkxs-1@yahoo.cn 展开
经典的话还加分!!!!!!!!!
tpkxs-1@yahoo.cn 展开
2个回答
展开全部
ToLin Lib "WinIo.dll" (ByVal PhysAddr As Long, ByVal PhysSize As Long, ByRef PhysMemHandle) As Long
Declare Function UnmapPhysicalMemory Lib "宽梁樱WinIo.dll" (ByVal PhysMemHandle, ByVal LinAddr) As Boolean
Declare Function GetPhysLong Lib "WinIo.dll" (ByVal PhysAddr As Long, ByRef PhysVal As Long) As Boolean
Declare Function SetPhysLong Lib "WinIo.dll" (ByVal PhysAddr As Long, ByVal PhysVal As Long) As Boolean
Declare Function GetPortVal Lib "WinIo.dll" (ByVal PortAddr As Integer, ByRef PortVal As Long, ByVal bSize As Byte) As Boolean
Declare Function SetPortVal Lib "WinIo.dll" (ByVal PortAddr As Integer, ByVal PortVal As Long, ByVal bSize As Byte) As Boolean
Declare Function InitializeWinIo Lib "WinIo.dll" () As Boolean
Declare Function ShutdownWinIo Lib "WinIo.dll" () As Boolean
Declare Function InstallWinIoDriver Lib "WinIo.dll" (ByVal DriverPath As String, ByVal Mode As Integer) As Boolean
Declare Function RemoveWinIoDriver Lib "WinIo.dll" () As Boolean
' ------------------------------------以上是WINIO函数声明-------------------------------------------
Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
'-----------------------------------以上是WIN32 API函数声明-----------------------------------------
再添加下面这个过程:
Sub KBCWait4IBE() '等待键盘缓冲渣蚂区为空
Dim dwVal As Long
Do
GetPortVal &H64, dwVal, 1
'这句表示从&H64端口读取一个字节并把读出的数据放到变量dwVal中
'GetPortVal函数的用法是GetPortVal 端口号,存放读出数据的变量,读入的长度
Loop While (dwVal And &H2)
End Sub
上面的是一个根据KBC规慎丛范写的过程,它的作用是在向键盘端口写入数据前等待一段时间,后面将会用到。
然后再添加如下过程,这2个过程用来模拟按键:
Public Const KBC_KEY_CMD = &H64 '键盘命令端口
Public Const KBC_KEY_DATA = &H60 '键盘数据端口
Sub MyKeyDown(ByVal vKeyCoad As Long)
'这个用来模拟按下键,参数vKeyCoad传入按键的虚拟码
Dim btScancode As Long
btScancode = MapVirtualKey(vKeyCoad, 0)
KBCWait4IBE '发送数据前应该先等待键盘缓冲区为空
SetPortVal KBC_KEY_CMD, &HD2, 1 '发送键盘写入命令
'SetPortVal函数用于向端口写入数据,它的用法是SetPortVal 端口号,欲写入的数据,写入数据的长度
KBCWait4IBE
SetPortVal KBC_KEY_DATA, btScancode, 1 '写入按键信息,按下键
End Sub
Declare Function UnmapPhysicalMemory Lib "宽梁樱WinIo.dll" (ByVal PhysMemHandle, ByVal LinAddr) As Boolean
Declare Function GetPhysLong Lib "WinIo.dll" (ByVal PhysAddr As Long, ByRef PhysVal As Long) As Boolean
Declare Function SetPhysLong Lib "WinIo.dll" (ByVal PhysAddr As Long, ByVal PhysVal As Long) As Boolean
Declare Function GetPortVal Lib "WinIo.dll" (ByVal PortAddr As Integer, ByRef PortVal As Long, ByVal bSize As Byte) As Boolean
Declare Function SetPortVal Lib "WinIo.dll" (ByVal PortAddr As Integer, ByVal PortVal As Long, ByVal bSize As Byte) As Boolean
Declare Function InitializeWinIo Lib "WinIo.dll" () As Boolean
Declare Function ShutdownWinIo Lib "WinIo.dll" () As Boolean
Declare Function InstallWinIoDriver Lib "WinIo.dll" (ByVal DriverPath As String, ByVal Mode As Integer) As Boolean
Declare Function RemoveWinIoDriver Lib "WinIo.dll" () As Boolean
' ------------------------------------以上是WINIO函数声明-------------------------------------------
Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
'-----------------------------------以上是WIN32 API函数声明-----------------------------------------
再添加下面这个过程:
Sub KBCWait4IBE() '等待键盘缓冲渣蚂区为空
Dim dwVal As Long
Do
GetPortVal &H64, dwVal, 1
'这句表示从&H64端口读取一个字节并把读出的数据放到变量dwVal中
'GetPortVal函数的用法是GetPortVal 端口号,存放读出数据的变量,读入的长度
Loop While (dwVal And &H2)
End Sub
上面的是一个根据KBC规慎丛范写的过程,它的作用是在向键盘端口写入数据前等待一段时间,后面将会用到。
然后再添加如下过程,这2个过程用来模拟按键:
Public Const KBC_KEY_CMD = &H64 '键盘命令端口
Public Const KBC_KEY_DATA = &H60 '键盘数据端口
Sub MyKeyDown(ByVal vKeyCoad As Long)
'这个用来模拟按下键,参数vKeyCoad传入按键的虚拟码
Dim btScancode As Long
btScancode = MapVirtualKey(vKeyCoad, 0)
KBCWait4IBE '发送数据前应该先等待键盘缓冲区为空
SetPortVal KBC_KEY_CMD, &HD2, 1 '发送键盘写入命令
'SetPortVal函数用于向端口写入数据,它的用法是SetPortVal 端口号,欲写入的数据,写入数据的长度
KBCWait4IBE
SetPortVal KBC_KEY_DATA, btScancode, 1 '写入按键信息,按下键
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
加两个timer,
在代码唯哗区加入,如下代码指指行:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim n
Private Sub Form_Load()
Timer1.Interval = 500
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyF11) Then
Timer2.Interval = 500
ElseIf GetAsyncKeyState(vbKeyF12) Then
Timer2.Interval = 0
End If
End Sub
Private Sub Timer2_Timer()
n = n + 1
If n = 1 Then SendKeys "T"
If n = 3 Then SendKeys "Y"
If n = 5 Then SendKeys "U"逗哪
If n = 8 Then n = 0
End Sub
在代码唯哗区加入,如下代码指指行:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim n
Private Sub Form_Load()
Timer1.Interval = 500
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyF11) Then
Timer2.Interval = 500
ElseIf GetAsyncKeyState(vbKeyF12) Then
Timer2.Interval = 0
End If
End Sub
Private Sub Timer2_Timer()
n = n + 1
If n = 1 Then SendKeys "T"
If n = 3 Then SendKeys "Y"
If n = 5 Then SendKeys "U"逗哪
If n = 8 Then n = 0
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询