这是一个可以通过AutoHotkey.dll(具有 COM 接口)到达。
你需要下载这个库,请移入c:\Windows\System32。
并注册系统(运行,% "regsvr32.exe AutoHotkey.dll",% "c:\Windows\System32")。
然后在 VS 中创建一个控制台应用程序项目,并选择 Project tab/Add reference。
在打开的窗口中找到 AutoHotkey 库,点击“添加”按钮,然后关闭窗口。
所以现在您已经在项目中连接了这个库,您将在参考文件夹中看到它。
在 Program.cs 中选择所有并替换此代码:
using System.Threading;
using AutoHotkey;
namespace work_with_AHK_object
{
class Program
{
static void Main()
{
/// write content for ahk script (thread)
string scriptContent=""
//+"#NoTrayIcon\n"
+"#KeyHistory, 0\n"
+"#NoEnv\n"
//+"ListLines, Off\n"
//+"DetectHiddenWindows, On\n"
//+"Process, Priority,, High\n"
+"SetBatchLines, -1\n"
+"SetMouseDelay, 25\n"
//+"Menu, Tray, Icon, % \"shell32.dll\", -153\n"
//+"WinSet, AlwaysOnTop, On, % \"ahk_id\"A_ScriptHwnd\n"
//+"WinSet, Style, -0xC00000, % \"ahk_id\"A_ScriptHwnd\n"
//+"WinMove, % \"ahk_id\"A_ScriptHwnd,, 888, 110, 914, 812\n"
//+"ListLines\n"
//+"ListLines, On\n"
+"TrayTip,, % \"Ready to use!\"\n" /// some notice
+""
+"Ins::\n"
+" Suspend\n"
+" Loop, % A_IsSuspended ? 1:2\n"
+" SoundBeep, 12500, 50\n"
+" KeyWait, % A_ThisHotkey\n"
+" Return\n"
+""
+"LButton::\n"
+" Loop\n"
+" Send, {Click}\n"
+" Until, !GetKeyState(\"LButton\", \"P\")\n"
+" Return\n"
+""
+"Space::\n"
+" Suspend, Off\n"
+" ExitApp";
/// initialize instance
CoCOMServer ahkThread=new CoCOMServer();
/// launch a script in a separate thread
ahkThread.ahktextdll(scriptContent);
/// wait for exit
while (ahkThread.ahkReady()!=0) Thread.Sleep(1000);
}
}
}
打开项目属性,在应用程序选项卡中将其输出类型更改为 Windows 应用程序。