We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,594 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

LuaInterface dll in WinForms

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.

Code:

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()
        {
            InitializeComponent();

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

        [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)
        {
            lua.DoString(textBox1.ToString());
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

    }
}
2
Contributors
2
Replies
20 Hours
Discussion Span
2 Years Ago
Last Updated
3
Views
Question
Answered
LuaMan
Newbie Poster
6 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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?

Momerath
Senior Poster
3,735 posts since Aug 2010
Reputation Points: 1,336
Solved Threads: 624
Skill Endorsements: 13

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().
                GetMethod("LeftClick"));
LuaMan
Newbie Poster
6 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 2 Years Ago by Momerath

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.2960 seconds using 2.67MB