添加项目文件。

This commit is contained in:
优雅的母鸡 2024-08-30 09:18:07 +08:00
parent bbbe84b90a
commit 96cf0eba9a
7 changed files with 222 additions and 0 deletions

25
鼠标连点器.sln Normal file
View File

@ -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

9
鼠标连点器/App.xaml Normal file
View File

@ -0,0 +1,9 @@
<Application x:Class="鼠标连点器.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:鼠标连点器"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View File

@ -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)
)]

View File

@ -0,0 +1,17 @@
<Window x:Class="鼠标连点器.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:鼠标连点器"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel>
<TextBlock Text="Press F8 to Start/Stop Clicking"
VerticalAlignment="Center" HorizontalAlignment="Center"
FontSize="16" FontWeight="Bold"/>
<Button x:Name="按钮" Content="0" Click="按钮_Click"/>
</StackPanel>
</Grid>
</Window>

View File

@ -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
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
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++;
}
}
}

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>