C#开发技巧之RPA网银密码安全组件输入(进阶版) 📅 发布时间:2026/9/4 9:31:41 👁 浏览次数: 不少客户在进行网银登录时常常会因为RPA无法填写密码而被劝退这是因为通常情况下我们调用系统API来模拟鼠标和键盘事件而非真实的鼠标键盘信号输入.所以这个操作很容易被网银插件等一系列插件屏蔽掉我们的操作如何解决最好的答案就是让硬件设备介入从底层操作给系统真实的鼠标按键信号.键鼠盒子硬件键鼠盒子是一款能够自动按键盘鼠标的纯硬件脚本工具由于是纯硬件可以有效避免检测封号病毒木马等问题确保使用的安全性以及在电脑前用双手可以完成的动作按键盒子都可以替代完成所以深受游戏打金的玩家喜爱。本次介绍的主角是键鼠盒子的一种幽灵键鼠 KM03、KM04低廉的价格丰富的接口调用使得扩展性和可玩性变得极高。1、C# 调用键鼠盒子的辅助类引用官方提供的Cdll文件gbild32.dll、gbild64.dll常用功能点using System; using System.Runtime.InteropServices; namespace ZhangYunYong.BankLib.Utils { /// summary /// 幽灵键鼠辅助类 /// /summary internal class GblidHelper { const string dll gbild32; // 设备操作 [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int opendevice(int index 0); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int opendevicebyid(int vid, int pid); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern int opendevicebypath(string path); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int isconnected(); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int resetdevice(); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int closedevice(); // 设备信息 [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern IntPtr getmodel(); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern IntPtr getserialnumber(); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern IntPtr getproductiondate(); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern IntPtr getfirmwareversion(); // 键盘操作 [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern int presskeybyname(string keyn); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int presskeybyvalue(int keyv); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern int releasekeybyname(string keyn); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int releasekeybyvalue(int keyv); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern int pressandreleasekeybyname(string keyn); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int pressandreleasekeybyvalue(int keyv); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern int iskeypressedbyname(string keyn); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int iskeypressedbyvalue(int keyv); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int releaseallkey(); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern int inputstring(string str); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int getcapslock(); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int getnumlock(); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int setpresskeydelay(int mind, int maxd); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int setinputstringintervaltime(int mind, int maxd); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int setcasesensitive(int cs); // 鼠标操作 [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int pressmousebutton(int mbtn); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int releasemousebutton(int mbtn); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int pressandreleasemousebutton(int mbtn); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int ismousebuttonpressed(int mbtn); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int releaseallmousebutton(); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int movemouseto(int x, int y); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int movemouserelative(int x, int y); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int movemousewheel(int z); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int getmousex(); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int getmousey(); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int setmouseposition(int x, int y); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int setpressmousebuttondelay(int mind, int maxd); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int setmousemovementdelay(int mind, int maxd); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int setmousemovementspeed(int speedvalue); [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int setmousemovementmode(int mode); // 加密狗操作 [DllImport(dll, CallingConvention CallingConvention.StdCall)] public static extern int initializedongle(); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern int setreadpassword(string writepwd, string newpwd); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern int setwritepassword(string oldpwd, string newpwd); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern IntPtr readstring(string readpwd, int addr, int count); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern int writestring(string writepwd, string str, int addr); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern int setcipher(string writepwd, string cipher); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern IntPtr encryptstring(string str); [DllImport(dll, CharSet CharSet.Ansi, CallingConvention CallingConvention.StdCall)] public static extern IntPtr decryptstring(string str); //模拟输入 public static void KeyPress(string content) { if (opendevice()1) { if (isconnected() 1) { setpresskeydelay(30, 100); setinputstringintervaltime(60, 200); pressandreleasekeybyname(content); closedevice(); } } } } }2. 常用实例1打开设备GblidHelper.opendevice();//1打开成功小于或等于0打开失败未找到指定设备2判断设备是否连接GblidHelper.isconnected();//1表示当前已连接设备0表示当前未连接3关闭设备GblidHelper.closedevice();//1关闭成功0关闭失败4复位设备GblidHelper.resetdevice();//1成功0失败5按下键GblidHelper.presskeybyname(c.ToString());//按下指定键6释放键GblidHelper.releasekeybyname(c.ToString());//释放按下的键7按下并释放键GblidHelper.pressandreleasekeybyname(c.ToString());//2表示成功0表示失败8释放所有按键当脚本比较复杂时可能不确定当前按下了哪些键可以使用该接口释放所有按下的键GblidHelper.releaseallkey();//释放所有按键9设置按键随机延时设置按键的随机延时即按下至释放之间的延时主要用于pressandreleasekeybyname、pressandreleasekeybyvalue和inputstring该功能无记忆软件每次启动都要重新设置否则将使用默认值.参数说明mind整数类型最小延时时间单位毫秒默认30maxd整数类型最大延时时间单位毫秒默认100进阶技巧通过此设置可以避免一些输入检查更像人工输入方式GblidHelper.setpresskeydelay(30, 100);10设置输入字符串随机延时设置输入字符串的间隔时间范围用于inputstring接口输入每个字符时的随机时间该功能无记忆软件每次启动都要重新设置否则将使用默认值。参数说明mind整数类型最小延时时间单位毫秒默认60maxd整数类型最大延时时间单位毫秒默认200进阶技巧通过此设置可以避免一些输入检查更像人工输入方式GblidHelper.setinputstringintervaltime(60, 200);11按下鼠标键鼠标键序号1:左键 2:中键 3:右键 4:侧键前 5:侧键后固件版本在1.0.1.0及以上的KM04支持侧键GblidHelper.pressmousebutton(1);12释放鼠标键鼠标键序号1:左键 2:中键 3:右键 4:侧键前 5:侧键后固件版本在1.0.1.0及以上的KM04支持侧键GblidHelper.releasemousebutton(1);13按下并释放鼠标键GblidHelper.pressandreleasemousebutton(1);14移动鼠标到指定坐标从当前位置移动鼠标到指定的坐标通过多次调用相对移动实现有轨迹不限移动范围。屏幕左上角坐标为0,0右下角坐标为屏幕分辨率值减1如800*600的屏幕分辨率有效坐标范围为0,0~799,599GblidHelper.movemouseto(30, 130);更多操作技巧见官方开放文档。