Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Threading;
- using System.Drawing;
- namespace Mousemove_advanced
- {
- /// <summary>
- /// Interaktionslogik für MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- Thread mousem, updatepb;
- int value = 0;
- string filePath;
- byte[] bytes = new byte[5];
- FileStream stream;
- public MainWindow()
- {
- InitializeComponent();
- filePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
- if (File.Exists(filePath + @"\MouseMove\TimeSetting.txt"))
- {
- cbSave.IsChecked = true;
- stream = new FileStream(filePath + @"\MouseMove\TimeSetting.txt", FileMode.Open);
- stream.Read(bytes, 0, 5);
- Slider.Value = bytes[0] + bytes[1] + bytes[2] + bytes[3] + bytes[4];
- }
- }
- private void btStart_Click(object sender, RoutedEventArgs e)
- {
- mousem = new Thread(new ParameterizedThreadStart(MouseM));
- mousem.Start(value);
- updatepb = new Thread(new ParameterizedThreadStart(UpdatePB));
- updatepb.Start(value);
- cvIndication.Background = System.Windows.Media.Brushes.Green;
- WindowState = WindowState.Minimized;
- btStart.Visibility = Visibility.Hidden;
- btStop.Visibility = Visibility.Visible;
- }
- private static void MouseM(object sleepTime)
- {
- try
- {
- System.Drawing.Point oldpoint;
- int elapsed;
- while (true)
- {
- elapsed = 0;
- do
- {
- oldpoint = new System.Drawing.Point(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y);
- Thread.Sleep(100);
- if (oldpoint == new System.Drawing.Point(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y))
- elapsed += 100;
- else
- elapsed = 0;
- } while (elapsed < (int)sleepTime * 985);
- System.Windows.Forms.Cursor.Position = new System.Drawing.Point(System.Windows.Forms.Cursor.Position.X - 1, System.Windows.Forms.Cursor.Position.Y);
- Thread.Sleep(10);
- System.Windows.Forms.Cursor.Position = new System.Drawing.Point(System.Windows.Forms.Cursor.Position.X + 1, System.Windows.Forms.Cursor.Position.Y);
- }
- }
- catch (Exception e) { }
- finally { }
- }
- private void UpdatePB(object sleepTime)
- {
- try
- {
- System.Drawing.Point oldpoint;
- int elapsed;
- while (true)
- {
- SetValue(0.0);
- elapsed = 0;
- do
- {
- oldpoint = new System.Drawing.Point(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y);
- Thread.Sleep(100);
- if (oldpoint == new System.Drawing.Point(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y))
- elapsed += 100;
- else
- elapsed = 0;
- if ((double)elapsed / ((int)sleepTime * 985) <= 1)
- SetValue(Math.Round((double)elapsed / ((int)sleepTime * 985), 3));
- } while (elapsed < (int)sleepTime * 985);
- }
- }
- catch (Exception e) { SetValue(0); }
- finally { }
- }
- private void SetValue(double value)
- {
- Dispatcher.Invoke(() =>
- {
- pbLoading.Value = value;
- lbElapsed.Content = $"{(value * 100).ToString("0.0")}%";
- });
- }
- private void btStop_Click(object sender, RoutedEventArgs e)
- {
- mousem.Interrupt();
- mousem.Join(100);
- updatepb.Interrupt();
- updatepb.Join(100);
- cvIndication.Background = System.Windows.Media.Brushes.Red;
- btStop.Visibility = Visibility.Hidden;
- btStart.Visibility = Visibility.Visible;
- }
- private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
- {
- if (lbTime != null)
- {
- lbTime.Content = $"{(int)Slider.Value / 60}min {(int)Slider.Value % 60}s";
- value = (int)Slider.Value;
- }
- }
- private void toByteArr(byte[] arr, int convvalue)
- {
- int rev = 0;
- while (convvalue > 0)
- {
- if (convvalue > 255)
- {
- convvalue -= 255;
- arr[rev] = 255;
- }
- else
- {
- arr[rev] = (byte)convvalue;
- convvalue = 0;
- }
- rev++;
- }
- }
- private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- try
- { stream.Close(); }
- catch (Exception a) { }
- try
- {
- mousem.Interrupt();
- mousem.Join(100);
- }
- catch (Exception a) { }
- try
- {
- updatepb.Interrupt();
- updatepb.Join(100);
- }
- catch (Exception a) { }
- if (cbSave.IsChecked == true)
- {
- if (File.Exists(filePath + @"\MouseMove\TimeSetting.txt"))
- File.Delete(filePath + @"\MouseMove\TimeSetting.txt");
- if (!Directory.Exists(filePath + @"\MouseMove"))
- Directory.CreateDirectory(filePath + @"\MouseMove");
- stream = new FileStream(filePath + @"\MouseMove\TimeSetting.txt", FileMode.Create);
- bytes = new byte[5];
- for (int i = 0; i < 5; i++)
- bytes[i] = 0;
- toByteArr(bytes, value);
- stream.Write(bytes, 0, 5);
- stream.Close();
- }
- else
- {
- try
- { Directory.Delete(filePath + @"\MouseMove", true); }
- catch (DirectoryNotFoundException a) { }
- finally { }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement