mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-11-23 01:39:17 +01:00
a66878498e
Record 360 controls using your DualShock 4 (PS: any old macros using hold control while running macro may be set to a new control when loaded, please re save your macro) Macro recording now happens in the select an action window instead of a separate one Save and Load Macro presets to use any time When recording with delays (recommend for X360 macros) you can double click on delays to edit the time When recording a new macro, previously saved Macros for that control are shown Many minor Macro fixes Giving major updates useless names that will never be seen outside of this changelog Icon Update Fixed shift modifier lightbar settings blocked off High DPI support (144+) Fixed various bugs at 120 DPI and higher When installing the ds4 driver, Actually checks if the driver got installed instead of always saying install complete
214 lines
8.7 KiB
C#
214 lines
8.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Runtime.InteropServices;
|
|
using DS4Library;
|
|
namespace DS4Control
|
|
{
|
|
public class Mouse : ITouchpadBehaviour
|
|
{
|
|
protected DateTime pastTime, firstTap, TimeofEnd;
|
|
protected Touch firstTouch, secondTouch;
|
|
private DS4State s = new DS4State();
|
|
protected int deviceNum;
|
|
private DS4Device dev = null;
|
|
private readonly MouseCursor cursor;
|
|
private readonly MouseWheel wheel;
|
|
private bool tappedOnce = false, secondtouchbegin = false;
|
|
public bool swipeLeft, swipeRight, swipeUp, swipeDown;
|
|
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;
|
|
|
|
public Mouse(int deviceID, DS4Device d)
|
|
{
|
|
deviceNum = deviceID;
|
|
dev = d;
|
|
cursor = new MouseCursor(deviceNum);
|
|
wheel = new MouseWheel(deviceNum);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return "Standard Mode";
|
|
}
|
|
|
|
public virtual void touchesMoved(object sender, TouchpadEventArgs arg)
|
|
{
|
|
cursor.touchesMoved(arg);
|
|
wheel.touchesMoved(arg);
|
|
if (!(swipeUp || swipeDown || swipeLeft || swipeRight))
|
|
{
|
|
if (arg.touches[0].hwX - firstTouch.hwX > 200) swipeRight = true;
|
|
if (arg.touches[0].hwX - firstTouch.hwX < -200) swipeLeft = true;
|
|
if (arg.touches[0].hwY - firstTouch.hwY > 100) swipeDown = true;
|
|
if (arg.touches[0].hwY - firstTouch.hwY < -100) swipeUp = true;
|
|
}
|
|
/*if ((swipeUp || swipeDown || swipeLeft || swipeRight))
|
|
Console.WriteLine("Up " + swipeUp + " Down " + swipeDown + " Left " + swipeLeft + " Right " + swipeRight);*/
|
|
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;
|
|
dev.getCurrentState(s);
|
|
synthesizeMouseButtons();
|
|
}
|
|
public virtual void touchesBegan(object sender, TouchpadEventArgs arg)
|
|
{
|
|
cursor.touchesBegan(arg);
|
|
wheel.touchesBegan(arg);
|
|
pastTime = arg.timeStamp;
|
|
firstTouch = arg.touches[0];
|
|
if (Global.getDoubleTap(deviceNum))
|
|
{
|
|
DateTime test = arg.timeStamp;
|
|
if (test <= (firstTap + TimeSpan.FromMilliseconds((double)Global.getTapSensitivity(deviceNum) * 1.5)) && !arg.touchButtonPressed)
|
|
secondtouchbegin = true;
|
|
}
|
|
dev.getCurrentState(s);
|
|
synthesizeMouseButtons();
|
|
}
|
|
public virtual void touchesEnded(object sender, TouchpadEventArgs arg)
|
|
{
|
|
slideright = slideleft = false;
|
|
swipeUp = swipeDown = swipeLeft = swipeRight = false;
|
|
if (Global.getTapSensitivity(deviceNum) != 0)
|
|
{
|
|
|
|
if (secondtouchbegin)
|
|
{
|
|
tappedOnce = false;
|
|
secondtouchbegin = false;
|
|
}
|
|
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
|
|
}
|
|
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);
|
|
//if (s.Touch1 || s.Touch2 || s.TouchButton)
|
|
synthesizeMouseButtons();
|
|
}
|
|
|
|
private DS4State remapped = new DS4State();
|
|
private void synthesizeMouseButtons()
|
|
{
|
|
if (Global.getCustomButton(deviceNum, DS4Controls.TouchLeft) == X360Controls.None &&
|
|
Global.getCustomMacro(deviceNum, DS4Controls.TouchLeft) == "0" &&
|
|
Global.getCustomKey(deviceNum, DS4Controls.TouchLeft) == 0 &&
|
|
leftDown)
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Left);
|
|
if (Global.getCustomButton(deviceNum, DS4Controls.TouchUpper) == X360Controls.None &&
|
|
Global.getCustomMacro(deviceNum, DS4Controls.TouchUpper) == "0" &&
|
|
Global.getCustomKey(deviceNum, DS4Controls.TouchUpper) == 0 &&
|
|
upperDown)
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Middle);
|
|
if (Global.getCustomButton(deviceNum, DS4Controls.TouchRight) == X360Controls.None &&
|
|
Global.getCustomMacro(deviceNum, DS4Controls.TouchRight) == "0" &&
|
|
Global.getCustomKey(deviceNum, DS4Controls.TouchRight) == 0 &&
|
|
rightDown)
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Left);
|
|
if (Global.getCustomButton(deviceNum, DS4Controls.TouchMulti) == X360Controls.None &&
|
|
Global.getCustomMacro(deviceNum, DS4Controls.TouchMulti) == "0" &&
|
|
Global.getCustomKey(deviceNum, DS4Controls.TouchMulti) == 0 &&
|
|
multiDown)
|
|
Mapping.MapClick(deviceNum, Mapping.Click.Right);
|
|
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);
|
|
s = remapped;
|
|
//remapped.CopyTo(s);
|
|
}
|
|
|
|
public virtual void touchButtonUp(object sender, TouchpadEventArgs arg)
|
|
{
|
|
pushed = DS4Controls.None;
|
|
upperDown = leftDown = rightDown = multiDown = false;
|
|
dev.setRumble(0, 0);
|
|
dev.getCurrentState(s);
|
|
if (s.Touch1 || s.Touch2)
|
|
synthesizeMouseButtons();
|
|
}
|
|
|
|
public virtual void touchButtonDown(object sender, TouchpadEventArgs arg)
|
|
{
|
|
//byte leftRumble, rightRumble;
|
|
if (arg.touches == null)
|
|
{
|
|
//No touches, finger on upper portion of touchpad
|
|
//leftRumble = rightRumble = 0;
|
|
upperDown = true;
|
|
}
|
|
else if (arg.touches.Length > 1 )//|| (Global.getLowerRCOn(deviceNum) && arg.touches[0].hwX > (1920 * 3) / 4 && arg.touches[0].hwY > (960 * 3) / 4))
|
|
{
|
|
//leftRumble = rightRumble = 150;
|
|
multiDown = true;
|
|
}
|
|
else
|
|
{
|
|
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;
|
|
}
|
|
else
|
|
{
|
|
}
|
|
}
|
|
dev.getCurrentState(s);
|
|
synthesizeMouseButtons();
|
|
}
|
|
|
|
public DS4State getDS4State()
|
|
{
|
|
return s;
|
|
}
|
|
}
|
|
}
|