-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Needs further testing
- Loading branch information
Showing
12 changed files
with
317 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace KeyToJoy.Input.LowLevel | ||
namespace KeyToJoy.Input.LowLevel | ||
{ | ||
// Source: https://stackoverflow.com/a/34384189 | ||
// Extra Info: | ||
// - http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx | ||
// - https://www.autoitscript.com/forum/topic/81761-callback-low-level-mouse-hook/ | ||
public enum MouseState | ||
{ | ||
Move = 0x0200, | ||
|
||
LeftButtonDown = 0x0201, | ||
LeftButtonUp = 0x0202, | ||
RightButtonDown = 0x0204, | ||
RightButtonUp = 0x0205, | ||
Wheel = 0x020A, | ||
WheelH = 0x020E, | ||
|
||
MiddleButtonDown = 0x0207, | ||
MiddleButtonUp = 0x0208, | ||
MiddleButtonDoubleClick = 0x0209, | ||
|
||
Wheel = 0x020A, // Wheel Up/Down | ||
WheelHorizontal = 0x020E, // Wheel Left/Right | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using System.Windows.Forms; | ||
using KeyToJoy.Input.LowLevel; | ||
using Linearstar.Windows.RawInput.Native; | ||
using Newtonsoft.Json; | ||
|
||
namespace KeyToJoy.Input | ||
{ | ||
internal class MouseBinding : Binding, IEquatable<MouseBinding> | ||
{ | ||
private const string MOUSE_SERIALIZE_PREFIX = "Mouse_"; | ||
|
||
private MouseButtons mouseButtons; | ||
|
||
[JsonConstructor] | ||
internal MouseBinding(string name) | ||
{ | ||
name = name.Substring(MOUSE_SERIALIZE_PREFIX.Length); | ||
this.mouseButtons = (MouseButtons)Enum.Parse(typeof(MouseButtons), name); | ||
} | ||
|
||
// TODO: Clean up (currently very prone to human error when adding buttons) | ||
// Note: Also add the other constructor: MouseBinding(MouseState mouseState) | ||
internal MouseBinding(RawMouseButtonFlags mouseButton) | ||
{ | ||
// TODO: Support up and down states seperately | ||
switch (mouseButton) | ||
{ | ||
case RawMouseButtonFlags.LeftButtonUp: | ||
case RawMouseButtonFlags.LeftButtonDown: | ||
this.mouseButtons = MouseButtons.Left; | ||
break; | ||
case RawMouseButtonFlags.RightButtonUp: | ||
case RawMouseButtonFlags.RightButtonDown: | ||
this.mouseButtons = MouseButtons.Right; | ||
break; | ||
case RawMouseButtonFlags.MiddleButtonUp: | ||
case RawMouseButtonFlags.MiddleButtonDown: | ||
this.mouseButtons = MouseButtons.Middle; | ||
break; | ||
// TODO: Support these (requires knowing low level input numbers for MouseState) | ||
//case RawMouseButtonFlags.Button4Up: | ||
//case RawMouseButtonFlags.Button4Down: | ||
// this.mouseButtons = MouseButtons.XButton1; | ||
// break; | ||
//case RawMouseButtonFlags.Button5Up: | ||
//case RawMouseButtonFlags.Button5Down: | ||
// this.mouseButtons = MouseButtons.XButton2; | ||
// break; | ||
default: throw new ArgumentOutOfRangeException(mouseButton.ToString()); | ||
} | ||
} | ||
|
||
// TODO: Clean up (currently very prone to human error when adding buttons) | ||
// Note: Also add the other constructor: MouseBinding(RawMouseButtonFlags mouseButton) | ||
public MouseBinding(MouseState mouseState) | ||
{ | ||
// TODO: Support up and down states seperately | ||
switch (mouseState) | ||
{ | ||
case MouseState.LeftButtonUp: | ||
case MouseState.LeftButtonDown: | ||
this.mouseButtons = MouseButtons.Left; | ||
break; | ||
case MouseState.RightButtonUp: | ||
case MouseState.RightButtonDown: | ||
this.mouseButtons = MouseButtons.Right; | ||
break; | ||
case MouseState.MiddleButtonUp: | ||
case MouseState.MiddleButtonDown: | ||
this.mouseButtons = MouseButtons.Middle; | ||
break; | ||
default: throw new ArgumentOutOfRangeException(mouseState.ToString()); | ||
} | ||
} | ||
|
||
internal override string GetUniqueBindingKey() | ||
{ | ||
return MOUSE_SERIALIZE_PREFIX + mouseButtons.ToString(); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if(!(obj is MouseBinding other)) | ||
return false; | ||
|
||
return Equals(other); | ||
} | ||
|
||
public bool Equals(MouseBinding other) | ||
{ | ||
return mouseButtons == other.mouseButtons; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return "(mouse) " + mouseButtons.ToString(); | ||
} | ||
|
||
public override object Clone() | ||
{ | ||
return MemberwiseClone(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.