Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - using System;
 - using System.Collections.Generic;
 - using System.ComponentModel;
 - using System.Data;
 - using System.Drawing;
 - using System.IO.Ports;
 - using System.Linq;
 - using System.Text;
 - using System.Threading.Tasks;
 - using System.Windows.Forms;
 - using System.Runtime.InteropServices;
 - namespace Arduino_W
 - {
 - public partial class Form1 : Form
 - {
 - public Form1()
 - {
 - InitializeComponent();
 - }
 - Boolean act = false;
 - private void Form1_Load(object sender, EventArgs e)
 - {
 - string[] ports = SerialPort.GetPortNames();
 - portBox.Items.AddRange(ports);
 - brBox.SelectedIndex = 0;
 - }
 - private void startstopBtn_Click(object sender, EventArgs e)
 - {
 - if(startstopBtn.Text == "Start")
 - {
 - try
 - {
 - sp.PortName = portBox.Text;
 - sp.BaudRate = Int32.Parse(brBox.Text);
 - sp.Open();
 - }
 - catch(Exception ex)
 - {
 - MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
 - }
 - if(sp.IsOpen)
 - {
 - act = true;
 - startstopBtn.Text = "Stop";
 - sendBtn.Enabled = true;
 - }
 - }
 - else
 - {
 - act = false;
 - startstopBtn.Text = "Start";
 - if(sp.IsOpen)
 - {
 - sp.Close();
 - }
 - }
 - }
 - private void portBox_SelectedIndexChanged(object sender, EventArgs e)
 - {
 - if(portBox.Text != "") startstopBtn.Enabled = true;
 - }
 - private void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
 - {
 - string data = sp.ReadLine();
 - if(data[0] == 'k') //key
 - {
 - SendKeys.SendWait(data.Substring(2, data.Length - 2));
 - }
 - else if(data[0] == 'm') //mouse
 - {
 - string ev = data.Substring(2, data.Length - 2);
 - switch (ev) {
 - case "lu":
 - MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftUp); break;
 - case "ld":
 - MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftDown); break;
 - case "mu":
 - MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.MiddleUp); break;
 - case "md":
 - MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.MiddleDown); break;
 - case "ru":
 - MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightUp); break;
 - case "rd":
 - MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightDown); break;
 - }
 - }
 - }
 - private void sendBtn_Click(object sender, EventArgs e)
 - {
 - sp.WriteLine(sendTxt.Text);
 - sendTxt.Text = "";
 - }
 - private void button1_Click(object sender, EventArgs e)
 - {
 - portBox.Items.AddRange(SerialPort.GetPortNames());
 - }
 - private void showtimeBox_CheckedChanged(object sender, EventArgs e)
 - {
 - }
 - private void readWnd_TextChanged(object sender, EventArgs e)
 - {
 - }
 - }
 - public class MouseOperations
 - {
 - [Flags]
 - public enum MouseEventFlags
 - {
 - LeftDown = 0x00000002,
 - LeftUp = 0x00000004,
 - MiddleDown = 0x00000020,
 - MiddleUp = 0x00000040,
 - Move = 0x00000001,
 - Absolute = 0x00008000,
 - RightDown = 0x00000008,
 - RightUp = 0x00000010
 - }
 - [DllImport("user32.dll", EntryPoint = "SetCursorPos")]
 - [return: MarshalAs(UnmanagedType.Bool)]
 - private static extern bool SetCursorPos(int x, int y);
 - [DllImport("user32.dll")]
 - [return: MarshalAs(UnmanagedType.Bool)]
 - private static extern bool GetCursorPos(out MousePoint lpMousePoint);
 - [DllImport("user32.dll")]
 - private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
 - public static void SetCursorPosition(int x, int y)
 - {
 - SetCursorPos(x, y);
 - }
 - public static void SetCursorPosition(MousePoint point)
 - {
 - SetCursorPos(point.X, point.Y);
 - }
 - public static MousePoint GetCursorPosition()
 - {
 - MousePoint currentMousePoint;
 - var gotPoint = GetCursorPos(out currentMousePoint);
 - if (!gotPoint) { currentMousePoint = new MousePoint(0, 0); }
 - return currentMousePoint;
 - }
 - public static void MouseEvent(MouseEventFlags value)
 - {
 - MousePoint position = GetCursorPosition();
 - mouse_event
 - ((int)value,
 - position.X,
 - position.Y,
 - 0,
 - 0)
 - ;
 - }
 - [StructLayout(LayoutKind.Sequential)]
 - public struct MousePoint
 - {
 - public int X;
 - public int Y;
 - public MousePoint(int x, int y)
 - {
 - X = x;
 - Y = y;
 - }
 - }
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment