以下是使用大漠插件绑定窗口的C#代码,以及间隔一秒按一次F1和F2的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace BindWindowExample
{
    class Program
    {
        [DllImport("dm.dll", EntryPoint = "BindWindow", CharSet = CharSet.Ansi, SetLastError = true)]
        public static extern int BindWindow(int hwnd, string display, string mouse, string keypad, int mode);

        [DllImport("dm.dll", EntryPoint = "KeyPress", CharSet = CharSet.Ansi, SetLastError = true)]
        public static extern int KeyPress(int keycode);

        static void Main(string[] args)
        {
            int hwnd = 12345; // 绑定的窗口句柄,需要替换成实际的值
            int bindResult = BindWindow(hwnd, 'normal', 'normal', 'normal', 0); // 绑定窗口
            if (bindResult == 1)
            {
                Console.WriteLine('绑定窗口成功!');
            }
            else
            {
                Console.WriteLine('绑定窗口失败,错误码:' + bindResult);
            }

            while (true)
            {
                KeyPress(112); // 模拟按下F1键
                System.Threading.Thread.Sleep(1000); // 等待1秒
                KeyPress(113); // 模拟按下F2键
                System.Threading.Thread.Sleep(1000); // 等待1秒
            }
        }
    }
}

需要注意的是,以上代码中的hwnd需要替换成实际的窗口句柄。另外,大漠插件的dm.dll文件需要放置在程序运行的目录下。


原文地址: https://www.cveoy.top/t/topic/oWcz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录