Hydrotronics

Virtual Input for VB.NET

Mar 5th, 2017
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.14 KB | None | 0 0
  1. 'Created By Hydrotronics
  2. Public Class VirtualInput
  3.  
  4.     Const LeftDown = &H2
  5.     Const LeftUp = &H4
  6.     Const MiddleDown = &H20
  7.     Const MiddleUp = &H40
  8.     Const RightDown = &H8
  9.     Const RightUp = &H10
  10.     Const Wheel As Integer = &H800
  11.     Const appCommand As UInteger = &H319
  12.     Const volumeUp As UInteger = &HA
  13.     Const volumeDown As UInteger = &H9
  14.     Const volumeMute As UInteger = &H8
  15.  
  16.  
  17.     Private Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Integer
  18.     Private Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As System.Drawing.Point) As Integer
  19.  
  20.     Private Declare Sub mouseclick Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
  21.  
  22.  
  23.     Private Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
  24.     End Function
  25.  
  26.     Public Shared Function SetMousePosition(ByVal x As Integer, ByVal y As Integer) As Boolean
  27.         SetCursorPos(x, y)
  28.         Return True
  29.     End Function
  30.  
  31.     Public Shared Function GetMousePosition() As System.Drawing.Point
  32.         Dim pos As New System.Drawing.Point()
  33.         Dim R As Long = GetCursorPos(pos)
  34.         Return pos
  35.     End Function
  36.  
  37.     Public Shared Function LeftClick() As Boolean
  38.         mouseclick(LeftDown, 0, 0, 0, 0)
  39.         mouseclick(LeftUp, 0, 0, 0, 0)
  40.         Return True
  41.     End Function
  42.  
  43.     Public Shared Function LeftClick(ByVal IsDouble As Boolean) As Boolean
  44.         mouseclick(LeftDown, 0, 0, 0, 0)
  45.         mouseclick(LeftUp, 0, 0, 0, 0)
  46.         If IsDouble Then
  47.             mouseclick(LeftDown, 0, 0, 0, 0)
  48.             mouseclick(LeftUp, 0, 0, 0, 0)
  49.         End If
  50.         Return True
  51.     End Function
  52.  
  53.     Public Shared Function RightClick() As Boolean
  54.         mouseclick(RightDown, 0, 0, 0, 0)
  55.         mouseclick(RightUp, 0, 0, 0, 0)
  56.         Return True
  57.     End Function
  58.  
  59.     Public Shared Function RightClick(ByVal IsDouble As Boolean) As Boolean
  60.         mouseclick(RightDown, 0, 0, 0, 0)
  61.         mouseclick(RightUp, 0, 0, 0, 0)
  62.         If IsDouble Then
  63.             mouseclick(RightDown, 0, 0, 0, 0)
  64.             mouseclick(RightUp, 0, 0, 0, 0)
  65.         End If
  66.         Return True
  67.     End Function
  68.  
  69.     Public Shared Function MiddleClick() As Boolean
  70.         mouseclick(MiddleDown, 0, 0, 0, 0)
  71.         mouseclick(MiddleUp, 0, 0, 0, 0)
  72.         Return True
  73.     End Function
  74.  
  75.     Public Shared Function MiddleClick(ByVal IsDouble As Boolean) As Boolean
  76.         mouseclick(MiddleDown, 0, 0, 0, 0)
  77.         mouseclick(MiddleUp, 0, 0, 0, 0)
  78.         If IsDouble Then
  79.             mouseclick(MiddleDown, 0, 0, 0, 0)
  80.             mouseclick(MiddleUp, 0, 0, 0, 0)
  81.         End If
  82.         Return True
  83.     End Function
  84.  
  85.     Public Shared Function DragTo(ByVal x As Integer, ByVal y As Integer) As Boolean
  86.         mouseclick(LeftDown, 0, 0, 0, 0)
  87.         SetCursorPos(x, y)
  88.         mouseclick(LeftUp, 0, 0, 0, 0)
  89.         Return True
  90.     End Function
  91.  
  92.     Public Shared Function ScrollDown(ByVal clicks As Integer) As Boolean
  93.         mouseclick(Wheel, 0, 0, -(clicks * 120), 0)
  94.         Return True
  95.     End Function
  96.  
  97.     Public Shared Function ScrollUp(ByVal clicks As Integer) As Boolean
  98.         mouseclick(Wheel, 0, 0, clicks * 120, 0)
  99.         Return True
  100.     End Function
  101.  
  102.     Public Shared Function QueueKeypress(ByVal Key As String) As Boolean
  103.         SendKeys.Send(Key)
  104.         Return True
  105.     End Function
  106.  
  107.     Public Function RaiseLocalVolume(ByVal amount As Integer, ByVal Instance As Form)
  108.         SendMessage(Instance.Handle, appCommand, &H30292, volumeUp * &H10000)
  109.  
  110.         Return True
  111.     End Function
  112.  
  113.     Public Function LowerLocalVolume(ByVal amount As Integer, ByVal Instance As Form)
  114.         SendMessage(Instance.Handle, appCommand, &H30292, volumeDown * &H10000)
  115.  
  116.         Return True
  117.     End Function
  118.  
  119.     Public Function MuteLocalVolume(ByVal Instance As Form)
  120.         SendMessage(Instance.Handle, appCommand, &H200EB0, volumeMute * &H10000)
  121.  
  122.         Return True
  123.     End Function
  124. End Class
Advertisement
Add Comment
Please, Sign In to add comment