Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Gma.System.MouseKeyHook;
- using System.Diagnostics;
- namespace MouseFixer
- {
- public class TheContext : ApplicationContext
- {
- // https://stackoverflow.com/questions/30061813/intercept-mouse-click
- StringBuilder logText;
- long lastClickTime;
- long lastMouseUp;
- bool ignoreClick = false;
- void writeLog(string msg)
- {
- logText.Append(msg + Environment.NewLine);
- File.AppendAllText("log.txt", logText.ToString());
- logText.Clear();
- }
- bool errorShown = false;
- void errorMsg(string str)
- {
- if(!errorShown)
- MessageBox.Show(str);
- errorShown = true;
- }
- long getTime()
- {
- return DateTimeOffset.Now.ToUnixTimeMilliseconds();
- }
- public TheContext()
- {
- Application.ApplicationExit += new EventHandler(this.OnExit);
- logText = new StringBuilder();
- lastClickTime = getTime();
- lastMouseUp = getTime();
- Hook.GlobalEvents().MouseDownExt += async (sender, e) =>
- {
- if (e.Button == MouseButtons.Left)
- {
- // e.Handled = true;
- // writeLog("Handling click DOWN! " + e.Delta);
- long lmu = (getTime() - lastMouseUp);
- if (lmu < 10)
- {
- Debug.WriteLine("Too fast click - ignoring " + (getTime() - lastMouseUp) + Environment.NewLine);
- e.Handled = true;
- ignoreClick = true;
- }
- long lct = getTime() - lastClickTime;
- lastClickTime = getTime();
- Debug.WriteLine("MouseDOWN " + lct + " ( " + lmu + " ) " + Environment.NewLine);
- }
- };
- Hook.GlobalEvents().MouseUpExt += async (sender, e) =>
- {
- if (e.Button == MouseButtons.Left)
- {
- if (!ignoreClick)
- {
- // e.Handled = true;
- // writeLog("Handling click UP! " + e.Delta);
- long lct = getTime() - lastClickTime;
- lastClickTime = getTime();
- Debug.WriteLine("MouseUP " + lct + Environment.NewLine);
- lastMouseUp = getTime();
- }
- else
- {
- Debug.WriteLine("Ignoring click " + Environment.NewLine);
- e.Handled = true;
- ignoreClick = false;
- }
- }
- };
- }
- private void OnExit(object sender, EventArgs e)
- {
- // File.AppendAllText("log.txt", logText.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement