2014-03-28 02:50:40 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2015-02-08 22:51:52 +01:00
|
|
|
|
|
|
|
|
|
namespace DS4Windows
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{
|
|
|
|
|
public class Mouse : ITouchpadBehaviour
|
|
|
|
|
{
|
2014-04-29 03:14:01 +02:00
|
|
|
|
protected DateTime pastTime, firstTap, TimeofEnd;
|
2014-06-02 19:29:38 +02:00
|
|
|
|
protected Touch firstTouch, secondTouch;
|
2014-04-27 21:32:09 +02:00
|
|
|
|
private DS4State s = new DS4State();
|
2014-03-28 02:50:40 +01:00
|
|
|
|
protected int deviceNum;
|
2014-04-27 21:32:09 +02:00
|
|
|
|
private DS4Device dev = null;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
private readonly MouseCursor cursor;
|
|
|
|
|
private readonly MouseWheel wheel;
|
2014-04-29 03:14:01 +02:00
|
|
|
|
private bool tappedOnce = false, secondtouchbegin = false;
|
2014-11-14 20:44:50 +01:00
|
|
|
|
public bool swipeLeft, swipeRight, swipeUp, swipeDown;
|
2014-11-15 22:54:14 +01:00
|
|
|
|
public byte swipeLeftB, swipeRightB, swipeUpB, swipeDownB, swipedB;
|
2014-10-31 00:56:51 +01:00
|
|
|
|
public bool slideleft, slideright;
|
|
|
|
|
// touch area stuff
|
|
|
|
|
public bool leftDown, rightDown, upperDown, multiDown;
|
|
|
|
|
protected DS4Controls pushed = DS4Controls.None;
|
|
|
|
|
protected Mapping.Click clicked = Mapping.Click.None;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
|
2014-04-27 21:32:09 +02:00
|
|
|
|
public Mouse(int deviceID, DS4Device d)
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{
|
|
|
|
|
deviceNum = deviceID;
|
2014-04-27 21:32:09 +02:00
|
|
|
|
dev = d;
|
2014-03-29 06:29:08 +01:00
|
|
|
|
cursor = new MouseCursor(deviceNum);
|
|
|
|
|
wheel = new MouseWheel(deviceNum);
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-28 06:47:26 +01:00
|
|
|
|
public virtual void sixaxisMoved(object sender, SixAxisEventArgs arg)
|
|
|
|
|
{
|
|
|
|
|
if (Global.UseSAforMouse[deviceNum])
|
|
|
|
|
{
|
|
|
|
|
bool triggeractivated = true;
|
|
|
|
|
int i = 0;
|
|
|
|
|
string[] ss = Global.SATriggers[deviceNum].Split(',');
|
|
|
|
|
//List<DS4Controls> ds4C = new List<DS4Controls>();
|
|
|
|
|
foreach (string s in ss)
|
|
|
|
|
if (!(int.TryParse(s, out i) && getDS4ControlsByName(i)))
|
|
|
|
|
triggeractivated = false;
|
|
|
|
|
if (triggeractivated)
|
|
|
|
|
cursor.sixaxisMoved(arg);
|
|
|
|
|
dev.getCurrentState(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool getDS4ControlsByName(int key)
|
|
|
|
|
{
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case 0: return s.Cross;
|
|
|
|
|
case 1: return s.Circle;
|
|
|
|
|
case 2: return s.Square;
|
|
|
|
|
case 3: return s.Triangle;
|
|
|
|
|
case 4: return s.L1;
|
|
|
|
|
case 5: return s.L2 > 127;
|
|
|
|
|
case 6: return s.R1;
|
|
|
|
|
case 7: return s.R2 > 127;
|
|
|
|
|
case 8: return s.DpadUp;
|
|
|
|
|
case 9: return s.DpadDown;
|
|
|
|
|
case 10: return s.DpadLeft;
|
|
|
|
|
case 11: return s.DpadRight;
|
|
|
|
|
case 12: return s.L3;
|
|
|
|
|
case 13: return s.R3;
|
|
|
|
|
case 14: return s.Touch1;
|
|
|
|
|
case 15: return s.Touch2;
|
|
|
|
|
case 16: return s.Options;
|
|
|
|
|
case 17: return s.Share;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-28 02:50:40 +01:00
|
|
|
|
public virtual void touchesMoved(object sender, TouchpadEventArgs arg)
|
|
|
|
|
{
|
2015-02-08 22:51:52 +01:00
|
|
|
|
if (!Global.UseTPforControls[deviceNum])
|
2014-11-14 20:44:50 +01:00
|
|
|
|
{
|
2015-06-01 21:04:22 +02:00
|
|
|
|
cursor.touchesMoved(arg, dragging || dragging2);
|
|
|
|
|
wheel.touchesMoved(arg, dragging || dragging2);
|
2014-11-14 20:44:50 +01:00
|
|
|
|
}
|
2014-11-15 22:54:14 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!(swipeUp || swipeDown || swipeLeft || swipeRight) && arg.touches.Length == 1)
|
|
|
|
|
{
|
2015-02-08 22:51:52 +01:00
|
|
|
|
if (arg.touches[0].hwX - firstTouch.hwX > 400) swipeRight = true;
|
|
|
|
|
if (arg.touches[0].hwX - firstTouch.hwX < -400) swipeLeft = true;
|
|
|
|
|
if (arg.touches[0].hwY - firstTouch.hwY > 300) swipeDown = true;
|
|
|
|
|
if (arg.touches[0].hwY - firstTouch.hwY < -300) swipeUp = true;
|
2014-11-15 22:54:14 +01:00
|
|
|
|
}
|
|
|
|
|
swipeUpB = (byte)Math.Min(255, Math.Max(0, (firstTouch.hwY - arg.touches[0].hwY) * 1.5f));
|
|
|
|
|
swipeDownB = (byte)Math.Min(255, Math.Max(0, (arg.touches[0].hwY - firstTouch.hwY) * 1.5f));
|
|
|
|
|
swipeLeftB = (byte)Math.Min(255, Math.Max(0, firstTouch.hwX - arg.touches[0].hwX));
|
|
|
|
|
swipeRightB = (byte)Math.Min(255, Math.Max(0, arg.touches[0].hwX - firstTouch.hwX));
|
|
|
|
|
}
|
|
|
|
|
if (Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 50 && arg.touches.Length == 2)
|
|
|
|
|
if (arg.touches[0].hwX - firstTouch.hwX > 200 && !slideleft)
|
|
|
|
|
slideright = true;
|
|
|
|
|
else if (firstTouch.hwX - arg.touches[0].hwX > 200 && !slideright)
|
|
|
|
|
slideleft = true;
|
2014-04-27 21:32:09 +02:00
|
|
|
|
dev.getCurrentState(s);
|
|
|
|
|
synthesizeMouseButtons();
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
public virtual void touchesBegan(object sender, TouchpadEventArgs arg)
|
|
|
|
|
{
|
2015-02-08 22:51:52 +01:00
|
|
|
|
if (!Global.UseTPforControls[deviceNum])
|
2014-11-15 22:54:14 +01:00
|
|
|
|
{
|
|
|
|
|
cursor.touchesBegan(arg);
|
|
|
|
|
wheel.touchesBegan(arg);
|
|
|
|
|
}
|
2014-03-28 02:50:40 +01:00
|
|
|
|
pastTime = arg.timeStamp;
|
|
|
|
|
firstTouch = arg.touches[0];
|
2015-02-08 22:51:52 +01:00
|
|
|
|
if (Global.DoubleTap[deviceNum])
|
2014-04-29 03:14:01 +02:00
|
|
|
|
{
|
|
|
|
|
DateTime test = arg.timeStamp;
|
2015-02-08 22:51:52 +01:00
|
|
|
|
if (test <= (firstTap + TimeSpan.FromMilliseconds((double)Global.TapSensitivity[deviceNum] * 1.5)) && !arg.touchButtonPressed)
|
2014-04-29 03:14:01 +02:00
|
|
|
|
secondtouchbegin = true;
|
|
|
|
|
}
|
2014-04-27 21:32:09 +02:00
|
|
|
|
dev.getCurrentState(s);
|
2014-11-15 22:54:14 +01:00
|
|
|
|
synthesizeMouseButtons();
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
public virtual void touchesEnded(object sender, TouchpadEventArgs arg)
|
|
|
|
|
{
|
2014-05-30 22:39:39 +02:00
|
|
|
|
slideright = slideleft = false;
|
2014-11-14 20:44:50 +01:00
|
|
|
|
swipeUp = swipeDown = swipeLeft = swipeRight = false;
|
2014-11-15 22:54:14 +01:00
|
|
|
|
swipeUpB = swipeDownB = swipeLeftB = swipeRightB = 0;
|
2015-02-08 22:51:52 +01:00
|
|
|
|
if (Global.TapSensitivity[deviceNum] != 0 && !Global.UseTPforControls[deviceNum])
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{
|
2014-04-29 03:14:01 +02:00
|
|
|
|
|
|
|
|
|
if (secondtouchbegin)
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{
|
2014-04-29 03:14:01 +02:00
|
|
|
|
tappedOnce = false;
|
|
|
|
|
secondtouchbegin = false;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
2014-04-29 03:14:01 +02:00
|
|
|
|
DateTime test = arg.timeStamp;
|
2015-02-08 22:51:52 +01:00
|
|
|
|
if (test <= (pastTime + TimeSpan.FromMilliseconds((double)Global.TapSensitivity[deviceNum] * 2)) && !arg.touchButtonPressed && !tappedOnce)
|
2014-04-29 03:14:01 +02:00
|
|
|
|
if (Math.Abs(firstTouch.hwX - arg.touches[0].hwX) < 10 && Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 10)
|
2015-02-08 22:51:52 +01:00
|
|
|
|
if (Global.DoubleTap[deviceNum])
|
2014-11-15 22:54:14 +01:00
|
|
|
|
{
|
|
|
|
|
tappedOnce = true;
|
|
|
|
|
firstTap = arg.timeStamp;
|
|
|
|
|
TimeofEnd = DateTime.Now; //since arg can't be used in synthesizeMouseButtons
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Left); //this way no delay if disabled
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
2014-04-27 21:32:09 +02:00
|
|
|
|
dev.getCurrentState(s);
|
|
|
|
|
synthesizeMouseButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isLeft(Touch t)
|
|
|
|
|
{
|
|
|
|
|
return t.hwX < 1920 * 2 / 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isRight(Touch t)
|
|
|
|
|
{
|
|
|
|
|
return t.hwX >= 1920 * 2 / 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void touchUnchanged(object sender, EventArgs unused)
|
|
|
|
|
{
|
|
|
|
|
dev.getCurrentState(s);
|
2014-04-29 03:14:01 +02:00
|
|
|
|
//if (s.Touch1 || s.Touch2 || s.TouchButton)
|
2014-11-15 22:54:14 +01:00
|
|
|
|
synthesizeMouseButtons();
|
2014-04-27 21:32:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DS4State remapped = new DS4State();
|
2015-06-01 21:04:22 +02:00
|
|
|
|
public bool dragging, dragging2;
|
2014-04-27 21:32:09 +02:00
|
|
|
|
private void synthesizeMouseButtons()
|
|
|
|
|
{
|
2014-11-04 04:44:55 +01:00
|
|
|
|
if (Global.getCustomButton(deviceNum, DS4Controls.TouchLeft) == X360Controls.None &&
|
2014-11-04 06:12:23 +01:00
|
|
|
|
Global.getCustomMacro(deviceNum, DS4Controls.TouchLeft) == "0" &&
|
|
|
|
|
Global.getCustomKey(deviceNum, DS4Controls.TouchLeft) == 0 &&
|
2014-11-04 04:44:55 +01:00
|
|
|
|
leftDown)
|
2015-06-01 21:04:22 +02:00
|
|
|
|
{
|
2014-10-21 04:31:13 +02:00
|
|
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Left);
|
2015-06-01 21:04:22 +02:00
|
|
|
|
dragging2 = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
dragging2 = false;
|
2014-11-04 04:44:55 +01:00
|
|
|
|
if (Global.getCustomButton(deviceNum, DS4Controls.TouchUpper) == X360Controls.None &&
|
2014-11-04 06:12:23 +01:00
|
|
|
|
Global.getCustomMacro(deviceNum, DS4Controls.TouchUpper) == "0" &&
|
|
|
|
|
Global.getCustomKey(deviceNum, DS4Controls.TouchUpper) == 0 &&
|
2014-11-04 04:44:55 +01:00
|
|
|
|
upperDown)
|
2014-10-21 04:31:13 +02:00
|
|
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Middle);
|
2014-11-04 04:44:55 +01:00
|
|
|
|
if (Global.getCustomButton(deviceNum, DS4Controls.TouchRight) == X360Controls.None &&
|
2014-11-04 06:12:23 +01:00
|
|
|
|
Global.getCustomMacro(deviceNum, DS4Controls.TouchRight) == "0" &&
|
|
|
|
|
Global.getCustomKey(deviceNum, DS4Controls.TouchRight) == 0 &&
|
2014-11-04 04:44:55 +01:00
|
|
|
|
rightDown)
|
2014-10-21 04:31:13 +02:00
|
|
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Left);
|
2014-11-04 04:44:55 +01:00
|
|
|
|
if (Global.getCustomButton(deviceNum, DS4Controls.TouchMulti) == X360Controls.None &&
|
2014-11-04 06:12:23 +01:00
|
|
|
|
Global.getCustomMacro(deviceNum, DS4Controls.TouchMulti) == "0" &&
|
|
|
|
|
Global.getCustomKey(deviceNum, DS4Controls.TouchMulti) == 0 &&
|
2014-11-04 04:44:55 +01:00
|
|
|
|
multiDown)
|
2014-10-21 04:31:13 +02:00
|
|
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Right);
|
2015-02-08 22:51:52 +01:00
|
|
|
|
if (!Global.UseTPforControls[deviceNum])
|
2014-04-29 03:14:01 +02:00
|
|
|
|
{
|
2014-11-15 22:54:14 +01:00
|
|
|
|
if (tappedOnce)
|
|
|
|
|
{
|
|
|
|
|
DateTime tester = DateTime.Now;
|
2015-02-08 22:51:52 +01:00
|
|
|
|
if (tester > (TimeofEnd + TimeSpan.FromMilliseconds((double)(Global.TapSensitivity[deviceNum]) * 1.5)))
|
2014-04-29 03:14:01 +02:00
|
|
|
|
{
|
2014-11-15 22:54:14 +01:00
|
|
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Left);
|
2014-04-29 03:14:01 +02:00
|
|
|
|
tappedOnce = false;
|
|
|
|
|
}
|
2014-11-15 22:54:14 +01:00
|
|
|
|
//if it fails the method resets, and tries again with a new tester value (gives tap a delay so tap and hold can work)
|
|
|
|
|
}
|
|
|
|
|
if (secondtouchbegin) //if tap and hold (also works as double tap)
|
2015-06-01 21:04:22 +02:00
|
|
|
|
{
|
2014-11-15 22:54:14 +01:00
|
|
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Left);
|
2015-06-01 21:04:22 +02:00
|
|
|
|
dragging = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
dragging = false;
|
2014-04-29 03:14:01 +02:00
|
|
|
|
}
|
2014-04-27 21:32:09 +02:00
|
|
|
|
s = remapped;
|
|
|
|
|
//remapped.CopyTo(s);
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void touchButtonUp(object sender, TouchpadEventArgs arg)
|
|
|
|
|
{
|
2014-04-27 21:32:09 +02:00
|
|
|
|
pushed = DS4Controls.None;
|
|
|
|
|
upperDown = leftDown = rightDown = multiDown = false;
|
|
|
|
|
dev.setRumble(0, 0);
|
|
|
|
|
dev.getCurrentState(s);
|
|
|
|
|
if (s.Touch1 || s.Touch2)
|
|
|
|
|
synthesizeMouseButtons();
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void touchButtonDown(object sender, TouchpadEventArgs arg)
|
|
|
|
|
{
|
|
|
|
|
if (arg.touches == null)
|
2014-04-27 21:32:09 +02:00
|
|
|
|
upperDown = true;
|
2014-11-15 22:54:14 +01:00
|
|
|
|
else if (arg.touches.Length > 1)
|
2014-04-27 21:32:09 +02:00
|
|
|
|
multiDown = true;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
2015-02-08 22:51:52 +01:00
|
|
|
|
if ((Global.LowerRCOn[deviceNum] && arg.touches[0].hwX > (1920 * 3) / 4 && arg.touches[0].hwY > (960 * 3) / 4))
|
2014-04-27 21:32:09 +02:00
|
|
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Right);
|
|
|
|
|
if (isLeft(arg.touches[0]))
|
|
|
|
|
leftDown = true;
|
|
|
|
|
else if (isRight(arg.touches[0]))
|
|
|
|
|
rightDown = true;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
2014-04-27 21:32:09 +02:00
|
|
|
|
dev.getCurrentState(s);
|
|
|
|
|
synthesizeMouseButtons();
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-27 21:32:09 +02:00
|
|
|
|
public DS4State getDS4State()
|
|
|
|
|
{
|
|
|
|
|
return s;
|
|
|
|
|
}
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|