AymenSekhri

Mouse Controller by IR (desktop part)

Sep 7th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.05 KB | None | 0 0
  1. Imports System.IO.Ports
  2.  
  3. Public Class Form1
  4.     Dim port As String = ""
  5.     Public Declare Sub mouse_event 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)
  6.     Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
  7.     Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
  8.     Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
  9.     Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
  10.     Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
  11.     Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
  12.     Dim com As IO.Ports.SerialPort = Nothing
  13.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  14.  
  15.         Control.CheckForIllegalCrossThreadCalls = False
  16.         Button1.Enabled = False
  17.         Button2.Enabled = True
  18.         Dim x As New Threading.Thread(AddressOf IRloop)
  19.         x.Start()
  20.     End Sub
  21.     Sub IRloop()
  22.         com = My.Computer.Ports.OpenSerialPort(port)
  23.         Dim last As String = "FFE21D"
  24.         While True
  25.             Try
  26.                 Dim buf As String = com.ReadLine()
  27.                 TextBox1.Text = TextBox1.Text & buf & vbNewLine
  28. re:
  29.                 If buf.Contains("FFE21D") Then 'left
  30.                     Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X - 15, Windows.Forms.Cursor.Position.Y)
  31.                     last = buf
  32.                 ElseIf buf.Contains("FF02FD") Then ' right
  33.                     Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X + 15, Windows.Forms.Cursor.Position.Y)
  34.                     last = buf
  35.                 ElseIf buf.Contains("FF609F") Then ' up
  36.                     Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y - 15)
  37.                     last = buf
  38.                 ElseIf buf.Contains("FF22DD") Then ' down
  39.                     Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y + 15)
  40.                     last = buf
  41.                 ElseIf buf.Contains("FFE01F") Then 'ok
  42.                     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
  43.                     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
  44.                     last = buf
  45.                 ElseIf buf.Contains("FFFFFFFF") Then ' repeat
  46.                     buf = last
  47.                     GoTo re
  48.                 End If
  49.                 TextBox1.SelectionStart = TextBox1.TextLength
  50.                 TextBox1.ScrollToCaret()
  51.             Catch ex As Exception
  52.                 MsgBox("Erorr :" & ex.Message)
  53.             End Try
  54.         End While
  55.     End Sub
  56.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  57.         port = "COM" & InputBox("Enter COM Number")
  58.  
  59.     End Sub
  60.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  61.         com.Close()
  62.         Button2.Enabled = False
  63.         Button1.Enabled = True
  64.     End Sub
  65. End Class
Add Comment
Please, Sign In to add comment