Start New Discussion within our Software Development Community

I am trying to make a macro engine for a personal project, and it would work fine, except that the form won't show when I debug it. Take it for granted that I am using the LuaInterface DLL please.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LuaInterface;
using System.Runtime.InteropServices;

namespace Lua_Macroez
    public partial class Form1 : Form
        public Form1()

            lua.RegisterFunction("MoveMouse", formStuff, formStuff.GetType().
                GetMethod("MoveMouse")); //Registers the mouse moving event
            lua.RegisterFunction("LeftCLick", formStuff, formStuff.GetType().

        [DllImport("User32.dll", SetLastError = true)]
        public static extern int SendInput(int nInputs, ref INPUT pInputs,
                                           int cbSize);

        //mouse event constants
        const int MOUSEEVENTF_LEFTDOWN = 2;
        const int MOUSEEVENTF_LEFTUP = 4;
        //input type constant
        const int INPUT_MOUSE = 0;

        Lua lua = new Lua(); //creates a new lua interpereter
        Form1 formStuff = new Form1(); 

        //This makes the functions that the lua executes later
        public void MoveMouse(int xval, int yval)
            Cursor.Position = new Point(xval, yval);

        public void LeftClick()
            //set up the INPUT struct and fill it for the mouse down
            INPUT i = new INPUT();
            i.type = INPUT_MOUSE;
            i.mi.dx = 0;
            i.mi.dy = 0;
            i.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
            i.mi.dwExtraInfo = IntPtr.Zero;
            i.mi.mouseData = 0;
            i.mi.time = 0;
            //send the input 
            SendInput(1, ref i, Marshal.SizeOf(i));
            //set the INPUT for mouse up and send it
            i.mi.dwFlags = MOUSEEVENTF_LEFTUP;
            SendInput(1, ref i, Marshal.SizeOf(i));

        //Function creation ends
        //struct that contains data for stuff
        public struct MOUSEINPUT
            public int dx;
            public int dy;
            public int mouseData;
            public int dwFlags;
            public int time;
            public IntPtr dwExtraInfo;

        public struct INPUT
            public uint type;
            public MOUSEINPUT mi;

        //structs end

        private void buttonExecute_Click(object sender, EventArgs e)

        private void Form1_Load(object sender, EventArgs e)



You do realize that formStuff is not the currently active form and is never shown in this code and it is the form you tie lua to?

Sheeeeit I figured out the problem.

lua.RegisterFunction("MoveMouse", this, this.GetType(). //<-- problem fixed
                GetMethod("MoveMouse")); //Registers the mouse moving event
            lua.RegisterFunction("LeftCLick", this, this.GetType().
This question has already been answered. Start a new discussion instead.