首页 > 解决方案 > Winform使用lua控制鼠标

问题描述

我尝试使用罗技鼠标发送字符串,就像罗技提供的软件一样
在此处输入图像描述

我单击转发按钮它会发送字符串,但我不能使用 winform 发送字符串给它来修改它

我发现罗技有G 系列 Lua API

我尝试使用 OnEvent 函数来控制鼠标点击发送字符串

但我以前从来没有Lua。

这是我的 C# 代码

using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LuaInterface;
namespace LuaScript
{
    public partial class Form1 : Form
    {
        public Lua lua = new Lua();
        string var = "aabbcc";
        public Form1()
        {
            InitializeComponent();
            lua.DoFile("logitechSendString.lua");
            object[] objs = lua.GetFunction("OnEvent").Call(this, var);
            lua.Close();
        }
    }
}

我的lua代码

function OnEvent(event, arg)
  if (arg!=null)then
    PressKey(arg) 
    ReleaseKey(arg)
    Sleep(50)
    PressMouseButton("Forward")
    ReleaseMouseButton("Forward")
  end
end

但它符合错误

System.IO.FileLoadException
  HResult=0x80131621
  Message=Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
  Source=LuaInterface
  StackTrace: 
   LuaInterface.Lua..ctor()
   LuaScript.Form1..ctor()  D:\Visual Studio\LuaScript\LuaScript\Form1.cs: 15
   LuaScript.Program.Main()  D:\Visual Studio\LuaScript\LuaScript\Program.cs:19

如何解决这个错误?

以及如何使用lua控制鼠标?

谢谢

标签: c#winformslualogitech-gaming-software

解决方案


这是一个没有 C# 的解决方案。
该字符串aabbcc存储在 LGS 脚本中。
在您的个人资料的子菜单中选择脚本并复制此 Lua 脚本:

-- when user presses middle mouse button, the following happens:
--   1. string "aabbcc" typing is simulated
--   2. "Forward" (X2) mouse button press and release simulated
function OnEvent(event, arg, family)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 3 then  -- middle mouse button pressed
      PressAndReleaseKey("a", "a", "b", "b", "c", "c")   -- change your string here
      Sleep(50)           -- 50 ms wait
      PressMouseButton(5) -- 5 = X2(Forward)
      Sleep(50)
      ReleaseMouseButton(5)
   end
end

要将字符串替换aabbcc为另一个字符串,您应该再次转到“脚本”菜单项,修改文本并保存(Ctrl-S)。


推荐阅读