From 96cf0eba9add0dcc5391350558b403b4d3fd8111 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E7=9A=84=E6=AF=8D=E9=B8=A1?=
<710521324@qq.com>
Date: Fri, 30 Aug 2024 09:18:07 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?=
=?UTF-8?q?=E4=BB=B6=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
鼠标连点器.sln | 25 +++++++
鼠标连点器/App.xaml | 9 +++
鼠标连点器/App.xaml.cs | 14 ++++
鼠标连点器/AssemblyInfo.cs | 10 +++
鼠标连点器/MainWindow.xaml | 17 +++++
鼠标连点器/MainWindow.xaml.cs | 136 ++++++++++++++++++++++++++++++++++
鼠标连点器/鼠标连点器.csproj | 11 +++
7 files changed, 222 insertions(+)
create mode 100644 鼠标连点器.sln
create mode 100644 鼠标连点器/App.xaml
create mode 100644 鼠标连点器/App.xaml.cs
create mode 100644 鼠标连点器/AssemblyInfo.cs
create mode 100644 鼠标连点器/MainWindow.xaml
create mode 100644 鼠标连点器/MainWindow.xaml.cs
create mode 100644 鼠标连点器/鼠标连点器.csproj
diff --git a/鼠标连点器.sln b/鼠标连点器.sln
new file mode 100644
index 0000000..543d2f2
--- /dev/null
+++ b/鼠标连点器.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.12.35209.166
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "鼠标连点器", "鼠标连点器\鼠标连点器.csproj", "{2BB14102-2872-4669-8DA6-0E3F9885341F}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {2BB14102-2872-4669-8DA6-0E3F9885341F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2BB14102-2872-4669-8DA6-0E3F9885341F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2BB14102-2872-4669-8DA6-0E3F9885341F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2BB14102-2872-4669-8DA6-0E3F9885341F}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {ADBE9A7B-7F20-4160-ABD0-7EF808C50355}
+ EndGlobalSection
+EndGlobal
diff --git a/鼠标连点器/App.xaml b/鼠标连点器/App.xaml
new file mode 100644
index 0000000..d247eea
--- /dev/null
+++ b/鼠标连点器/App.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/鼠标连点器/App.xaml.cs b/鼠标连点器/App.xaml.cs
new file mode 100644
index 0000000..80bda25
--- /dev/null
+++ b/鼠标连点器/App.xaml.cs
@@ -0,0 +1,14 @@
+using System.Configuration;
+using System.Data;
+using System.Windows;
+
+namespace 鼠标连点器
+{
+ ///
+ /// Interaction logic for App.xaml
+ ///
+ public partial class App : Application
+ {
+ }
+
+}
diff --git a/鼠标连点器/AssemblyInfo.cs b/鼠标连点器/AssemblyInfo.cs
new file mode 100644
index 0000000..b0ec827
--- /dev/null
+++ b/鼠标连点器/AssemblyInfo.cs
@@ -0,0 +1,10 @@
+using System.Windows;
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
diff --git a/鼠标连点器/MainWindow.xaml b/鼠标连点器/MainWindow.xaml
new file mode 100644
index 0000000..b148ef6
--- /dev/null
+++ b/鼠标连点器/MainWindow.xaml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
diff --git a/鼠标连点器/MainWindow.xaml.cs b/鼠标连点器/MainWindow.xaml.cs
new file mode 100644
index 0000000..36c75b9
--- /dev/null
+++ b/鼠标连点器/MainWindow.xaml.cs
@@ -0,0 +1,136 @@
+using System.Drawing;
+using System.Runtime.InteropServices;
+using System.Text;
+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;
+
+namespace 鼠标连点器
+{
+ ///
+ /// Interaction logic for MainWindow.xaml
+ ///
+ public partial class MainWindow : Window
+ {
+ // Windows API constants
+ private const int MOUSEEVENTF_LEFTDOWN = 0x02;
+ private const int MOUSEEVENTF_LEFTUP = 0x04;
+ private const int WH_KEYBOARD_LL = 13;
+ private const int WM_KEYDOWN = 0x0100;
+ private const int VK_F8 = 0x77; // Virtual key code for F8
+
+ // Importing necessary Windows API functions
+ [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
+ public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
+
+ [DllImport("user32.dll")]
+ static extern bool GetCursorPos(out POINT lpPoint);
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct POINT
+ {
+ public int X;
+ public int Y;
+ }
+
+ [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+ private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
+
+ [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static extern bool UnhookWindowsHookEx(IntPtr hhk);
+
+ [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+ private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
+
+ [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+ private static extern IntPtr GetModuleHandle(string lpModuleName);
+
+ // Delegate for low-level keyboard proc
+ private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
+
+ private LowLevelKeyboardProc _proc;
+ private IntPtr _hookID = IntPtr.Zero;
+
+ // Timer for clicking
+ private Timer clickTimer;
+ private bool isClicking = false;
+
+ public MainWindow()
+ {
+ InitializeComponent();
+ _proc = HookCallback;
+ _hookID = SetHook(_proc);
+ }
+
+ private IntPtr SetHook(LowLevelKeyboardProc proc)
+ {
+ using (var curProcess = System.Diagnostics.Process.GetCurrentProcess())
+ using (var curModule = curProcess.MainModule)
+ {
+ return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
+ }
+ }
+
+ private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
+ {
+ if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
+ {
+ int vkCode = Marshal.ReadInt32(lParam);
+
+ if (vkCode == VK_F8)
+ {
+ if (isClicking)
+ {
+ StopClicking();
+ }
+ else
+ {
+ StartClicking();
+ }
+ }
+ }
+
+ return CallNextHookEx(_hookID, nCode, wParam, lParam);
+ }
+
+ private void StartClicking()
+ {
+ isClicking = true;
+ clickTimer = new Timer(ClickMouse, null, 0, 50); // Click every 100 ms (adjust as needed)
+ }
+
+ private void StopClicking()
+ {
+ isClicking = false;
+ if (clickTimer != null)
+ {
+ clickTimer.Dispose();
+ }
+ }
+
+ private void ClickMouse(object state)
+ {
+ GetCursorPos(out POINT cursorPos);
+ mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, cursorPos.X, cursorPos.Y, 0, 0);
+ }
+
+ protected override void OnClosed(EventArgs e)
+ {
+ UnhookWindowsHookEx(_hookID);
+ base.OnClosed(e);
+ }
+ int i = 0;
+ private void 按钮_Click(object sender, RoutedEventArgs e)
+ {
+ (sender as Button).Content = i.ToString();
+ i++;
+ }
+ }
+}
\ No newline at end of file
diff --git a/鼠标连点器/鼠标连点器.csproj b/鼠标连点器/鼠标连点器.csproj
new file mode 100644
index 0000000..e3e33e3
--- /dev/null
+++ b/鼠标连点器/鼠标连点器.csproj
@@ -0,0 +1,11 @@
+
+
+
+ WinExe
+ net8.0-windows
+ enable
+ enable
+ true
+
+
+