2014-03-28 02:50:40 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using DS4Library;
|
|
|
|
|
namespace DS4Control
|
|
|
|
|
{
|
|
|
|
|
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-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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return "Standard Mode";
|
|
|
|
|
}
|
2014-05-30 22:39:39 +02:00
|
|
|
|
public bool slideleft, slideright;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
public virtual void touchesMoved(object sender, TouchpadEventArgs arg)
|
|
|
|
|
{
|
2014-03-29 06:29:08 +01:00
|
|
|
|
cursor.touchesMoved(arg);
|
2014-06-09 01:41:36 +02:00
|
|
|
|
wheel.touchesMoved(arg);
|
2014-06-02 19:29:38 +02:00
|
|
|
|
if (Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 50)
|
|
|
|
|
if (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-06-06 22:38:52 +02:00
|
|
|
|
//if (arg.touches.Length == 2)
|
|
|
|
|
// Console.WriteLine("Left " + slideleft + " Right " + slideright);
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
public virtual void touchesBegan(object sender, TouchpadEventArgs arg)
|
|
|
|
|
{
|
2014-03-29 06:29:08 +01:00
|
|
|
|
cursor.touchesBegan(arg);
|
|
|
|
|
wheel.touchesBegan(arg);
|
2014-03-28 02:50:40 +01:00
|
|
|
|
pastTime = arg.timeStamp;
|
|
|
|
|
firstTouch = arg.touches[0];
|
2014-04-29 03:14:01 +02:00
|
|
|
|
if (Global.getDoubleTap(deviceNum))
|
|
|
|
|
{
|
|
|
|
|
DateTime test = arg.timeStamp;
|
|
|
|
|
if (test <= (firstTap + TimeSpan.FromMilliseconds((double)Global.getTapSensitivity(deviceNum) * 1.5)) && !arg.touchButtonPressed)
|
|
|
|
|
secondtouchbegin = true;
|
|
|
|
|
}
|
2014-04-27 21:32:09 +02:00
|
|
|
|
dev.getCurrentState(s);
|
2014-04-29 03:14:01 +02:00
|
|
|
|
synthesizeMouseButtons();
|
2014-04-27 21:32:09 +02:00
|
|
|
|
//Console.WriteLine(arg.timeStamp.ToString("O") + " " + "began at " + arg.touches[0].hwX + "," + arg.touches[0].hwY);
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
public virtual void touchesEnded(object sender, TouchpadEventArgs arg)
|
|
|
|
|
{
|
2014-04-27 21:32:09 +02:00
|
|
|
|
//Console.WriteLine(arg.timeStamp.ToString("O") + " " + "ended at " + arg.touches[0].hwX + "," + arg.touches[0].hwY);
|
2014-05-30 22:39:39 +02:00
|
|
|
|
slideright = slideleft = false;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
if (Global.getTapSensitivity(deviceNum) != 0)
|
|
|
|
|
{
|
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;
|
|
|
|
|
if (test <= (pastTime + TimeSpan.FromMilliseconds((double)Global.getTapSensitivity(deviceNum) * 2)) && !arg.touchButtonPressed && !tappedOnce)
|
|
|
|
|
if (Math.Abs(firstTouch.hwX - arg.touches[0].hwX) < 10 && Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 10)
|
|
|
|
|
if (Global.getDoubleTap(deviceNum))
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
//if (buttonLock)
|
|
|
|
|
synthesizeMouseButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected DS4Controls pushed = DS4Controls.None;
|
|
|
|
|
protected Mapping.Click clicked = Mapping.Click.None;
|
|
|
|
|
|
|
|
|
|
// touch area stuff
|
2014-04-29 03:14:01 +02:00
|
|
|
|
public bool leftDown, rightDown, upperDown, multiDown;
|
2014-04-27 21:32:09 +02:00
|
|
|
|
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-04-27 21:32:09 +02:00
|
|
|
|
synthesizeMouseButtons();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DS4State remapped = new DS4State();
|
|
|
|
|
private void synthesizeMouseButtons()
|
|
|
|
|
{
|
Shift modifier: Hold an action to use another set of controls, if nothing is set to the shifted control, in falls back to the default action
View input of controls in profiles, see exactly when a deadzone is passed and check the input delay for controllers (special thanks to jhebbel), click the on sixaxis panel
Click the Empty text on in the lightbar box to copy the lightbar color from full to empty.
While opened, option to keep the window size after closing the profile's settings
Old profiles are automatically upgraded if it's missing new settings, such as how colors are now saved, sixaxis deadzones, and shift controls
Other UI changes for profile settings, flipped touchpad and other settings boxes
Others:
Fix for when clicking the semicolon in the select an action screen
Fix assigning Sixaxis action to a key
minor UI changes and bug fixes, such as auto resize of the log listview
DS4Updater: Also now works for the new numbering system, can read the version number right from the exe instead of in profiles.xml, UI additions to better notify users of errors, Bug fixes for non-portable users
2014-07-07 21:22:42 +02:00
|
|
|
|
//Mapping.MapCustom(deviceNum, s, remapped, null);
|
2014-04-27 21:32:09 +02:00
|
|
|
|
if (leftDown)
|
|
|
|
|
Mapping.MapTouchpadButton(deviceNum, DS4Controls.TouchLeft, Mapping.Click.Left, remapped);
|
|
|
|
|
if (upperDown)
|
|
|
|
|
Mapping.MapTouchpadButton(deviceNum, DS4Controls.TouchUpper, Mapping.Click.Middle, remapped);
|
|
|
|
|
if (rightDown)
|
|
|
|
|
Mapping.MapTouchpadButton(deviceNum, DS4Controls.TouchRight, Mapping.Click.Left, remapped);
|
|
|
|
|
if (multiDown)
|
|
|
|
|
Mapping.MapTouchpadButton(deviceNum, DS4Controls.TouchMulti, Mapping.Click.Right, remapped);
|
2014-04-29 03:14:01 +02:00
|
|
|
|
if (tappedOnce)
|
|
|
|
|
{
|
|
|
|
|
DateTime tester = DateTime.Now;
|
|
|
|
|
if (tester > (TimeofEnd + TimeSpan.FromMilliseconds((double)(Global.getTapSensitivity(deviceNum)) * 1.5)))
|
|
|
|
|
{
|
|
|
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Left);
|
|
|
|
|
tappedOnce = false;
|
|
|
|
|
}
|
|
|
|
|
//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)
|
|
|
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Left);
|
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)
|
|
|
|
|
{
|
2014-04-27 21:32:09 +02:00
|
|
|
|
//byte leftRumble, rightRumble;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
if (arg.touches == null)
|
|
|
|
|
{
|
|
|
|
|
//No touches, finger on upper portion of touchpad
|
2014-04-27 21:32:09 +02:00
|
|
|
|
//leftRumble = rightRumble = 0;
|
|
|
|
|
upperDown = true;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
2014-04-27 21:32:09 +02:00
|
|
|
|
else if (arg.touches.Length > 1 )//|| (Global.getLowerRCOn(deviceNum) && arg.touches[0].hwX > (1920 * 3) / 4 && arg.touches[0].hwY > (960 * 3) / 4))
|
2014-03-28 02:50:40 +01:00
|
|
|
|
{
|
2014-04-27 21:32:09 +02:00
|
|
|
|
//leftRumble = rightRumble = 150;
|
|
|
|
|
multiDown = true;
|
2014-03-28 02:50:40 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-04-27 21:32:09 +02:00
|
|
|
|
if ((Global.getLowerRCOn(deviceNum) && arg.touches[0].hwX > (1920 * 3) / 4 && arg.touches[0].hwY > (960 * 3) / 4))
|
|
|
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Right);
|
|
|
|
|
if (isLeft(arg.touches[0]))
|
|
|
|
|
{
|
|
|
|
|
leftDown = true;
|
|
|
|
|
//leftRumble = 25;
|
|
|
|
|
//rightRumble = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (isRight(arg.touches[0]))
|
|
|
|
|
{
|
|
|
|
|
rightDown = true;
|
|
|
|
|
//leftRumble = 0;
|
|
|
|
|
//rightRumble = 25;
|
|
|
|
|
}
|
2014-03-28 02:50:40 +01:00
|
|
|
|
else
|
2014-04-27 21:32:09 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|