Advertisement
CorrM

KeyChecker

Nov 22nd, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.14 KB | None | 0 0
  1. Imports System.Runtime.InteropServices
  2.  
  3. Class KeyChecker
  4.  
  5.     Public Event HandleKeyPersed(ByVal vKey As System.Windows.Forms.Keys)
  6.     Dim KeysToHandle As New ArrayList
  7.  
  8.     <DllImport("user32.dll")>
  9.     Shared Function GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys) As Short
  10.     End Function
  11.  
  12.     Sub Start()
  13.         Dim T As New Threading.Thread(Sub()
  14.                                           While True
  15.                                               For Each xKey As System.Windows.Forms.Keys In KeysToHandle
  16.                                                   If GetAsyncKeyState(xKey) > 0 Then
  17.                                                       RaiseEvent HandleKeyPersed(xKey)
  18.                                                   End If
  19.                                               Next
  20.                                               Threading.Thread.Sleep(700)
  21.                                           End While
  22.                                       End Sub) With {.IsBackground = True} : T.Start()
  23.     End Sub
  24.  
  25.     Sub HandleThisKey(ByVal Key As System.Windows.Forms.Keys)
  26.         KeysToHandle.Add(Key)
  27.     End Sub
  28. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement