Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Sunday, August 2, 2015

Programming

Initial Programming Post

Do you want to see this stuff?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AutoInputer
{
    public partial class AutoInputer : Form
    {        //Grabs the user32.dll for the mouse and keyboard events.
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

        private const int m_mouseLeftDown = 2;
        private const int m_mouseLeftUp = 4;
        private const int m_mouseRightDown = 8;
        private const int m_mouseRightUp = 10;

        private int m_runLimit = 0;

        public AutoInputer()
        {
            InitializeComponent();
        }

        private void intervalBar_ValueChanged(object sender, EventArgs e)
        {
            intervalText.Text = intervalBar.Value.ToString();
        }

        private void intervalText_TextChanged(object sender, EventArgs e)
        {
            try
            {
                int temp = int.Parse(intervalText.Text);

                if (temp <= 0)
                {
                    temp = 1;
                }
            }
            catch
            {
                intervalText.Text = "1";
            }
        }

        private void runLimitText_TextChanged(object sender, EventArgs e)
        {
            try
            {
                int temp = int.Parse(runLimitText.Text);

                if (temp <= 0)
                {
                    temp = 1;
                }
            }
            catch
            {
                runLimitText.Text = "1";
            }
        }

        private void goButton_Click(object sender, EventArgs e)
        {
            GoEvent();
        }

        private void GoEvent()
        {
            stringText.Enabled = false;
            eventTypePanel.Enabled = false;
            eventQueryPanel.Enabled = false;
            intervalText.Enabled = false;
            intervalBar.Enabled = false;
            goButton.Enabled = false;
            stopButton.Enabled = true;

            intervalTimer.Enabled = true;
            intervalTimer.Interval = int.Parse(intervalText.Text);

            statusLabel.Text = "Running";

            m_runLimit = int.Parse(runLimitText.Text);
        }

        private void stopButton_Click(object sender, EventArgs e)
        {
            StopEvent();
        }

        private void StopEvent()
        {
            stringText.Enabled = true;
            eventTypePanel.Enabled = true;
            eventQueryPanel.Enabled = true;
            intervalText.Enabled = true;
            intervalBar.Enabled = true;
            goButton.Enabled = true;
            stopButton.Enabled = false;

            intervalTimer.Enabled = false;

            statusLabel.Text = "Stopped";
        }

        private void opacityBar_Scroll(object sender, EventArgs e)
        {
            Double temp = opacityBar.Value;
            Opacity = temp / 100;

            if (Opacity <= .05)
            {
                Opacity = .05;
            }
            if (Opacity >= 1)
            {
                Opacity = 1;
            }
        }

        private void intervalTimer_Tick(object sender, EventArgs e)
        {
            bool temp = bool.Parse(Control.IsKeyLocked(Keys.Scroll).ToString());
         
            if ((scrollLockGoRadio.Checked == true) && (temp == false) || (runLimitCheck.Checked && (m_runLimit <= 0)))
            {
                if (runLimitCheck.Checked && (m_runLimit <= 0))
                {
                    StopEvent();
                }

                return;
            }
            else
            {
                int x = 100;
                int y = 100;
                string c = intervalText.Text;

                if (runLimitCheck.Checked)
                {
                    --m_runLimit;
                }

                if (stringRadio.Checked)
                {
                    SendKeys.Send(stringText.Text);
                    return;
                }
                if (leftMouseClickRadio.Checked)
                {
                    mouse_event(m_mouseLeftDown, x, y, 0, 0);
                    mouse_event(m_mouseLeftUp, x, y, 0, 0);
                    return;
                }
                if (rightMouseClickRadio.Checked)
                {
                    mouse_event(m_mouseRightDown, x, y, 0, 0);
                    mouse_event(m_mouseRightUp, x, y, 0, 0);
                    return;
                }
            }
        }
    }
}

This program was built to simulate a mouse-click or typing a letter or phrase (auto-clicker). An interval is given on how fast the function would run. In the image above, the phrase "Type Here" would be typed 10 times a second (1 every 100 milliseconds).