【问题标题】:Winform use lua to control MouseWinform使用lua控制鼠标
【发布时间】:2020-06-07 04:09:48
【问题描述】:

我尝试用罗技鼠标发送字符串之类的罗技提供的软件来做

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

我发现罗技有G-series 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控制鼠标?

谢谢

【问题讨论】:

  • G 系列 Lua API 仅适用于在罗技游戏软件中运行的 Lua 脚本。外部程序(如您的 C# 程序)无法访问此 API。
  • 模拟mouse button #5 X2(Forward) 按下并释放你根本不需要Lua。这可以在 C# 中本地完成。
  • 如果您只是想在按下鼠标按钮 Forward 时模拟输入一些消息,那么您需要在 Logitech 游戏软件中创建一个宏(在您的图片)。通过拖放宏名称将创建的宏绑定到鼠标按钮。
  • 嗨 Evor 感谢您的回答我尝试使用 sg300 因为它包含内存它可以存储来自 winform 的字符串我只需要它来存储字符串并通过点击鼠标发送,或者我可以简单地模拟点击和发送字符串.

标签: c# winforms lua logitech-gaming-software


【解决方案1】:

这是一个没有 C# 的解决方案。
字符串aabbcc 存储在 LGS 脚本中。
在您的个人资料的子菜单中选择 Scripting 并复制此 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)。

【讨论】:

    猜你喜欢
    • 2021-11-11
    • 2023-04-04
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 2022-10-20
    • 2010-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多