Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO.Ports
- Public Class Form1
- Dim port As String = ""
- 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)
- Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
- Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
- Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
- Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
- Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
- Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
- Dim com As IO.Ports.SerialPort = Nothing
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Control.CheckForIllegalCrossThreadCalls = False
- Button1.Enabled = False
- Button2.Enabled = True
- Dim x As New Threading.Thread(AddressOf IRloop)
- x.Start()
- End Sub
- Sub IRloop()
- com = My.Computer.Ports.OpenSerialPort(port)
- Dim last As String = "FFE21D"
- While True
- Try
- Dim buf As String = com.ReadLine()
- TextBox1.Text = TextBox1.Text & buf & vbNewLine
- re:
- If buf.Contains("FFE21D") Then 'left
- Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X - 15, Windows.Forms.Cursor.Position.Y)
- last = buf
- ElseIf buf.Contains("FF02FD") Then ' right
- Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X + 15, Windows.Forms.Cursor.Position.Y)
- last = buf
- ElseIf buf.Contains("FF609F") Then ' up
- Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y - 15)
- last = buf
- ElseIf buf.Contains("FF22DD") Then ' down
- Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y + 15)
- last = buf
- ElseIf buf.Contains("FFE01F") Then 'ok
- mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
- mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
- last = buf
- ElseIf buf.Contains("FFFFFFFF") Then ' repeat
- buf = last
- GoTo re
- End If
- TextBox1.SelectionStart = TextBox1.TextLength
- TextBox1.ScrollToCaret()
- Catch ex As Exception
- MsgBox("Erorr :" & ex.Message)
- End Try
- End While
- End Sub
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- port = "COM" & InputBox("Enter COM Number")
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- com.Close()
- Button2.Enabled = False
- Button1.Enabled = True
- End Sub
- End Class
Add Comment
Please, Sign In to add comment