Skip to content

Commit 2f362be

Browse files
Merge remote-tracking branch 'remotes/origin/ReadAndWriteMouseWheelState'
2 parents 829f87d + d706b0a commit 2f362be

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

FreePIE.Core.Plugins/MousePlugin.cs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using FreePIE.Core.Contracts;
66
using FreePIE.Core.Plugins.Strategies;
77
using SlimDX.DirectInput;
8+
using SlimDX.RawInput;
89

910
namespace FreePIE.Core.Plugins
1011
{
@@ -15,6 +16,8 @@ public class MousePlugin : Plugin
1516
// Mouse position state variables
1617
private double deltaXOut;
1718
private double deltaYOut;
19+
private int wheel;
20+
public const int WheelMax = 120;
1821

1922
private DirectInput directInputInstance = new DirectInput();
2023
private Mouse mouseDevice;
@@ -70,16 +73,6 @@ public override string FriendlyName
7073
get { return "Mouse"; }
7174
}
7275

73-
public override bool GetProperty(int index, IPluginProperty property)
74-
{
75-
return false;
76-
}
77-
78-
public override bool SetProperties(Dictionary<string, object> properties)
79-
{
80-
return true;
81-
}
82-
8376
static private MouseKeyIO.MOUSEINPUT MouseInput(int x, int y, uint data, uint t, uint flag)
8477
{
8578
var mi = new MouseKeyIO.MOUSEINPUT {dx = x, dy = y, mouseData = data, time = t, dwFlags = flag};
@@ -89,12 +82,12 @@ static private MouseKeyIO.MOUSEINPUT MouseInput(int x, int y, uint data, uint t,
8982
public override void DoBeforeNextExecute()
9083
{
9184
// If a mouse command was given in the script, issue it all at once right here
92-
if ((int)deltaXOut != 0 || (int)deltaYOut != 0)
85+
if ((int)deltaXOut != 0 || (int)deltaYOut != 0 || wheel != 0)
9386
{
9487

9588
var input = new MouseKeyIO.INPUT[1];
9689
input[0].type = MouseKeyIO.INPUT_MOUSE;
97-
input[0].mi = MouseInput((int)deltaXOut, (int)deltaYOut, 0, 0, MouseKeyIO.MOUSEEVENTF_MOVE);
90+
input[0].mi = MouseInput((int)deltaXOut, (int)deltaYOut, (uint)wheel, 0, MouseKeyIO.MOUSEEVENTF_MOVE | MouseKeyIO.MOUSEEVENTF_WHEEL);
9891

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

@@ -107,6 +100,8 @@ public override void DoBeforeNextExecute()
107100
{
108101
deltaYOut = deltaYOut - (int)deltaYOut;
109102
}
103+
104+
wheel = 0;
110105
}
111106

112107
currentMouseState = null; // flush the mouse state
@@ -121,15 +116,7 @@ public double DeltaX
121116
deltaXOut = deltaXOut + value;
122117
}
123118

124-
get
125-
{
126-
// Retrieve the mouse state only once per iteration to avoid getting
127-
// zeros on subsequent calls
128-
if (currentMouseState == null)
129-
currentMouseState = mouseDevice.GetCurrentState();
130-
131-
return currentMouseState.X;
132-
}
119+
get { return CurrentMouseState.X; }
133120
}
134121

135122
public double DeltaY
@@ -139,26 +126,30 @@ public double DeltaY
139126
deltaYOut = deltaYOut + value;
140127
}
141128

129+
get { return CurrentMouseState.Y; }
130+
}
131+
132+
public int Wheel
133+
{
134+
get { return CurrentMouseState.Z; }
135+
set { wheel = value; }
136+
137+
}
138+
139+
private MouseState CurrentMouseState
140+
{
142141
get
143142
{
144-
// Retrieve the mouse state only once per iteration to avoid getting
145-
// zeros on subsequent calls
146143
if (currentMouseState == null)
147144
currentMouseState = mouseDevice.GetCurrentState();
148145

149-
return currentMouseState.Y;
146+
return currentMouseState;
150147
}
151148
}
152149

153150
public bool IsButtonDown(int index)
154151
{
155-
156-
// Retrieve the mouse state only once per iteration to avoid getting
157-
// zeros on subsequent calls
158-
if (currentMouseState == null)
159-
currentMouseState = mouseDevice.GetCurrentState();
160-
161-
return currentMouseState.IsPressed(index);
152+
return CurrentMouseState.IsPressed(index);
162153
}
163154

164155
public bool IsButtonPressed(int button)
@@ -242,6 +233,11 @@ public class MouseGlobal : UpdateblePluginGlobal<MousePlugin>
242233
{
243234
public MouseGlobal(MousePlugin plugin) : base(plugin) { }
244235

236+
public int wheelMax
237+
{
238+
get { return MousePlugin.WheelMax; }
239+
}
240+
245241
public double deltaX
246242
{
247243
get { return plugin.DeltaX; }
@@ -254,6 +250,12 @@ public double deltaY
254250
set { plugin.DeltaY = value; }
255251
}
256252

253+
public int wheel
254+
{
255+
get { return plugin.Wheel; }
256+
set { plugin.Wheel = value; }
257+
}
258+
257259
public bool leftButton
258260
{
259261
get { return plugin.IsButtonDown(0); }

0 commit comments

Comments
 (0)