Winform use lua to control Mouse

0

I try to use Logitech mouse to send string like logitech provide a software to do
enter image description here

I click Forward button it will send string but I can't use winform to send string to it to modify it

I find logitech has G-series Lua API

I try to use OnEvent function to control mouse click to send string

But I never Lua before.

Here is my c# code

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();
        }
    }
}

My lua code

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

But it complie error

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

How to solve this error?

And How to do use lua to control Mouse?

Thanks

c#
winforms
lua
logitech-gaming-software
asked on Stack Overflow Feb 23, 2020 by 5407 • edited Feb 23, 2020 by Egor Skriptunoff

1 Answer

1

This is a solution without C#.
The string aabbcc is stored in the LGS script.
In your profile's submenu select Scripting and copy this Lua script:

-- 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

To replace string aabbcc with another one, you should again go to "Scripting" menu item, modify the text and save it (Ctrl-S).

answered on Stack Overflow Feb 23, 2020 by Egor Skriptunoff

User contributions licensed under CC BY-SA 3.0