Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions FreePIE.Core.Plugins/MousePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using FreePIE.Core.Plugins.Strategies;
using SlimDX.DirectInput;
using SlimDX.RawInput;
using System.Windows.Forms;
using System.Drawing;

namespace FreePIE.Core.Plugins
{
Expand All @@ -16,6 +18,8 @@ public class MousePlugin : Plugin
// Mouse position state variables
private double deltaXOut;
private double deltaYOut;
public float absoluteX = -1;
public float absoluteY = -1;
private int wheel;
public const int WheelMax = 120;

Expand Down Expand Up @@ -82,12 +86,29 @@ static private MouseKeyIO.MOUSEINPUT MouseInput(int x, int y, uint data, uint t,
public override void DoBeforeNextExecute()
{
// If a mouse command was given in the script, issue it all at once right here
if ((int)deltaXOut != 0 || (int)deltaYOut != 0 || wheel != 0)
if ((int)deltaXOut != 0 || (int)deltaYOut != 0 || wheel != 0 || absoluteX != 0 || absoluteY != 0)
{

var input = new MouseKeyIO.INPUT[1];
input[0].type = MouseKeyIO.INPUT_MOUSE;
input[0].mi = MouseInput((int)deltaXOut, (int)deltaYOut, (uint)wheel, 0, MouseKeyIO.MOUSEEVENTF_MOVE | MouseKeyIO.MOUSEEVENTF_WHEEL);
if (absoluteX != -1 || absoluteY != -1)
{
if (absoluteX == -1)
{
absoluteX = (float)Cursor.Position.X / SystemInformation.VirtualScreen.Width * 65535+1;
}

if (absoluteY == -1)
{
absoluteY = (float)Cursor.Position.Y / SystemInformation.VirtualScreen.Height * 65535+1;
}

input[0].mi = MouseInput((int)absoluteX, (int)absoluteY, (uint)wheel, 0, MouseKeyIO.MOUSEEVENTF_MOVE | MouseKeyIO.MOUSEEVENTF_WHEEL | MouseKeyIO.MOUSEEVENTF_ABSOLUTE);
}
else
{
input[0].mi = MouseInput((int)deltaXOut, (int)deltaYOut, (uint)wheel, 0, MouseKeyIO.MOUSEEVENTF_MOVE | MouseKeyIO.MOUSEEVENTF_WHEEL);
}

MouseKeyIO.SendInput(1, input, Marshal.SizeOf(input[0].GetType()));

Expand All @@ -100,9 +121,11 @@ public override void DoBeforeNextExecute()
{
deltaYOut = deltaYOut - (int)deltaYOut;
}


absoluteX = -1;
absoluteY = -1;
wheel = 0;
}
}

currentMouseState = null; // flush the mouse state

Expand Down Expand Up @@ -260,6 +283,17 @@ public double deltaY
set { plugin.DeltaY = value; }
}

public int x
{
get { return Cursor.Position.X; }
set { plugin.absoluteX = (float)value / SystemInformation.VirtualScreen.Width * 65535; }
}
public int y
{
get { return Cursor.Position.Y; }
set { plugin.absoluteY = (float)value / SystemInformation.VirtualScreen.Height * 65535; }
}

public int wheel
{
get { return plugin.Wheel; }
Expand Down