Ok, wow yeah - that was MUCH easier than I thought it to be. Thank you Xesttub!
[code:1]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
namespace MouseCage
{
public partial class Form1 : Form
{
public int Top = 100;
public int Bottom = 500;
public int Left = 100;
public int Right = 500;
String hotkey = "k";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
FileStream file = new FileStream("mousecage.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(file);
string s = sr.ReadLine();
Top = Int16.Parse(s);
s = sr.ReadLine();
Bottom = Int16.Parse(s);
s = sr.ReadLine();
Left = Int16.Parse(s);
s = sr.ReadLine();
Right = Int16.Parse(s);
s = sr.ReadLine();
hotkey = s;
sr.Close();
file.Close();
}
catch
{
MessageBox.Show("mousecage.txt missing");
}
}
private void timer1_Tick(object sender, EventArgs e)
{
Point p = System.Windows.Forms.Cursor.Position;
if (System.Windows.Forms.Cursor.Position.Y <= Top)
p.Y = Top;
if (System.Windows.Forms.Cursor.Position.Y >= Bottom)
p.Y = Bottom;
if (System.Windows.Forms.Cursor.Position.X <= Left)
p.X = Left;
if (System.Windows.Forms.Cursor.Position.X >= Right)
p.X = Right;
System.Windows.Forms.Cursor.Position = p;
}
private void Form1_DoubleClick(object sender, EventArgs e)
{
timer1.Enabled = !timer1.Enabled;
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar.ToString() == hotkey)
timer1.Enabled = !timer1.Enabled;
}
}
}[/code:1]
Connect With Us