c# - 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# 的解决方案。
该字符串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)。
推荐阅读
- javascript - Vue.js - 需要在不重新加载的情况下切换方向(rtl 到 ltr,反之亦然)
- haskell - 最小固定点,最大固定点
- constructor - Kotlin 语法糖:在构造函数中将 var 设为私有
- hibernate - JPA:如何将 LocalDateTime 转换为 LocalDate
- c - 为什么我需要将 NUL 字符附加到数组?
- content-security-policy - “宽松”的 Content-Security-Policy 有多大用处
- python - 如何创建具有给定指数 gamma 的幂律分布无标度网络
- loops - 跳出kotlin中的for循环
- r - 为什么这个简单的回归(keras)人工神经网络失败得如此糟糕?
- php - 如何在 zend 框架 1.12 中包含引导 css 文件