mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-11-23 01:39:17 +01:00
b4a6249fa3
Significant CPU usage decrease by reworking how single instances work, on a mobile i7 for example with a single controller connected usage went from 4-6% to .5-1.5%. With no controllers connected the usage went from 2.5-4.5% to 0%! As mentioned before, single instances has been reworked, so trying to relaunch DS4W more reliably opens the previous instance Fixed Shift modifier not working if main controls were not modified Fixed Tilt Left for Shift modifier Fixed default text of shift controls Remove touchpad movement notification when swipe for controls is enabled Can test the rumble motors separately via Heavy and Light Truly implemented Flush HID (I think) Slight change in profiles, when loading profiles in for the first time in this new version, there may be a slight delay Updated French Translations Removed mouse moving as an option for touch swipes controls, as they weren't implemented nor have a purpose to be
867 lines
38 KiB
C#
867 lines
38 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using DS4Control;
|
|
using DS4Library;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
namespace DS4Windows
|
|
{
|
|
public partial class RecordBox : Form
|
|
{
|
|
private DS4Control.Control scpDevice;
|
|
Stopwatch sw = new Stopwatch();
|
|
Timer ds4 = new Timer();
|
|
public List<int> macros = new List<int>();
|
|
public List<string> macronames = new List<string>();
|
|
KBM360 kbm;
|
|
DS4State cState;
|
|
public bool saved = false;
|
|
List<DS4Controls> dcs = new List<DS4Controls>();
|
|
public RecordBox(KBM360 op, DS4Control.Control bus_device)
|
|
{
|
|
scpDevice = bus_device;
|
|
kbm = op;
|
|
InitializeComponent();
|
|
if (op != null)
|
|
if (kbm.macrorepeat)
|
|
cBStyle.SelectedIndex = 1;
|
|
else
|
|
cBStyle.SelectedIndex = 0;
|
|
ds4.Tick += ds4_Tick;
|
|
ds4.Interval = 1;
|
|
dcs.Add(DS4Controls.Cross);
|
|
dcs.Add(DS4Controls.Cross);
|
|
dcs.Add(DS4Controls.Circle);
|
|
dcs.Add(DS4Controls.Square);
|
|
dcs.Add(DS4Controls.Triangle);
|
|
dcs.Add(DS4Controls.Options);
|
|
dcs.Add(DS4Controls.Share);
|
|
dcs.Add(DS4Controls.DpadUp);
|
|
dcs.Add(DS4Controls.DpadDown);
|
|
dcs.Add(DS4Controls.DpadLeft);
|
|
dcs.Add(DS4Controls.DpadRight);
|
|
dcs.Add(DS4Controls.PS);
|
|
dcs.Add(DS4Controls.L1);
|
|
dcs.Add(DS4Controls.R1);
|
|
dcs.Add(DS4Controls.L2);
|
|
dcs.Add(DS4Controls.R2);
|
|
dcs.Add(DS4Controls.L3);
|
|
dcs.Add(DS4Controls.R3);
|
|
dcs.Add(DS4Controls.LXPos);
|
|
dcs.Add(DS4Controls.LXNeg);
|
|
dcs.Add(DS4Controls.LYPos);
|
|
dcs.Add(DS4Controls.LYNeg);
|
|
dcs.Add(DS4Controls.RXPos);
|
|
dcs.Add(DS4Controls.RXNeg);
|
|
dcs.Add(DS4Controls.RYPos);
|
|
dcs.Add(DS4Controls.RYNeg);
|
|
if (kbm.macrostag.Count > 0)
|
|
{
|
|
macros.AddRange(kbm.macrostag);
|
|
LoadMacro();
|
|
saved = true;
|
|
}
|
|
}
|
|
|
|
void ds4_Tick(object sender, EventArgs e)
|
|
{
|
|
if (scpDevice.DS4Controllers[0] != null)
|
|
{
|
|
cState = scpDevice.getDS4State(0);
|
|
if (btnRecord.Text == Properties.Resources.StopText)
|
|
foreach (DS4Controls dc in dcs)
|
|
if (Mapping.getBoolMapping(dc, cState, null, null))
|
|
{
|
|
int value = DS4ControltoInt(dc);
|
|
int count = 0;
|
|
foreach (int i in macros)
|
|
{
|
|
if (i == value)
|
|
count++;
|
|
}
|
|
if (macros.Count == 0)
|
|
{
|
|
macros.Add(value);
|
|
lVMacros.Items.Add(DS4ControltoX360(dc), 0);
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
}
|
|
else if (count % 2 == 0)
|
|
{
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
macros.Add((int)sw.ElapsedMilliseconds + 300);
|
|
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", sw.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
macros.Add(value);
|
|
lVMacros.Items.Add(DS4ControltoX360(dc), 0);
|
|
}
|
|
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
|
|
}
|
|
else if (!Mapping.getBoolMapping(dc, cState, null, null))
|
|
{
|
|
if (macros.Count != 0)
|
|
{
|
|
int value = DS4ControltoInt(dc);
|
|
int count = 0;
|
|
foreach (int i in macros)
|
|
{
|
|
if (i == value)
|
|
count++;
|
|
}
|
|
/*for (int i = macros.Count - 1; i >= 0; i--)
|
|
if (macros.Count == 261)
|
|
count++;*/
|
|
if (count % 2 == 1)
|
|
{
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
macros.Add((int)sw.ElapsedMilliseconds + 300);
|
|
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", sw.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
macros.Add(value);
|
|
lVMacros.Items.Add(DS4ControltoX360(dc), 1);
|
|
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static int DS4ControltoInt(DS4Controls ctrl)
|
|
{
|
|
switch (ctrl)
|
|
{
|
|
case DS4Controls.Cross: return 261;
|
|
case DS4Controls.Circle: return 262;
|
|
case DS4Controls.Square: return 263;
|
|
case DS4Controls.Triangle: return 264;
|
|
case DS4Controls.Options: return 265;
|
|
case DS4Controls.Share: return 266;
|
|
case DS4Controls.DpadUp: return 267;
|
|
case DS4Controls.DpadDown: return 268;
|
|
case DS4Controls.DpadLeft: return 269;
|
|
case DS4Controls.DpadRight: return 270;
|
|
case DS4Controls.PS: return 271;
|
|
case DS4Controls.L1: return 272;
|
|
case DS4Controls.R1: return 273;
|
|
case DS4Controls.L2: return 274;
|
|
case DS4Controls.R2: return 275;
|
|
case DS4Controls.L3: return 276;
|
|
case DS4Controls.R3: return 277;
|
|
case DS4Controls.LXPos: return 278;
|
|
case DS4Controls.LXNeg: return 279;
|
|
case DS4Controls.LYPos: return 280;
|
|
case DS4Controls.LYNeg: return 281;
|
|
case DS4Controls.RXPos: return 282;
|
|
case DS4Controls.RXNeg: return 283;
|
|
case DS4Controls.RYPos: return 284;
|
|
case DS4Controls.RYNeg: return 285;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static string DS4ControltoX360(DS4Controls ctrl)
|
|
{
|
|
switch (ctrl)
|
|
{
|
|
case DS4Controls.Cross: return "A Button";
|
|
case DS4Controls.Circle: return "B Button";
|
|
case DS4Controls.Square: return "X Button";
|
|
case DS4Controls.Triangle: return "Y Button";
|
|
case DS4Controls.Options: return "Start";
|
|
case DS4Controls.Share: return "Back";
|
|
case DS4Controls.DpadUp: return "Up Button";
|
|
case DS4Controls.DpadDown: return "Down Button";
|
|
case DS4Controls.DpadLeft: return "Left Button";
|
|
case DS4Controls.DpadRight: return "Right Button";
|
|
case DS4Controls.PS: return "Guide";
|
|
case DS4Controls.L1: return "Left Bumper";
|
|
case DS4Controls.R1: return "Right Bumper";
|
|
case DS4Controls.L2: return "Left Trigger";
|
|
case DS4Controls.R2: return "Right Trigger";
|
|
case DS4Controls.L3: return "Left Stick";
|
|
case DS4Controls.R3: return "Right Stick";
|
|
case DS4Controls.LXPos: return "LS Right";
|
|
case DS4Controls.LXNeg: return "LS Left";
|
|
case DS4Controls.LYPos: return "LS Down";
|
|
case DS4Controls.LYNeg: return "LS Up";
|
|
case DS4Controls.RXPos: return "RS Right";
|
|
case DS4Controls.RXNeg: return "RS Left";
|
|
case DS4Controls.RYPos: return "RS Down";
|
|
case DS4Controls.RYNeg: return "RS Up";
|
|
}
|
|
return "None";
|
|
}
|
|
|
|
private void btnRecord_Click(object sender, EventArgs e)
|
|
{
|
|
if (btnRecord.Text == Properties.Resources.RecordText)
|
|
{
|
|
if (cBRecordDelays.Checked)
|
|
sw.Start();
|
|
scpDevice.recordingMacro = true;
|
|
saved = false;
|
|
ds4.Start();
|
|
macros.Clear();
|
|
lVMacros.Items.Clear();
|
|
btnRecord.Text = Properties.Resources.StopText;
|
|
EnableControls(false);
|
|
ActiveControl = null;
|
|
lVMacros.Focus();
|
|
}
|
|
else
|
|
{
|
|
scpDevice.recordingMacro = false;
|
|
ds4.Stop();
|
|
if (btn4th.Text.Contains(Properties.Resources.UpText))
|
|
btn4th_Click(sender, e);
|
|
if (btn5th.Text.Contains(Properties.Resources.UpText))
|
|
btn5th_Click(sender, e);
|
|
if (cBRecordDelays.Checked)
|
|
sw.Reset();
|
|
if (cBRecordDelays.Checked)
|
|
lbDelayTip.Visible = true;
|
|
btnRecord.Text = Properties.Resources.RecordText;
|
|
EnableControls(true);
|
|
}
|
|
}
|
|
|
|
private void EnableControls(bool on)
|
|
{
|
|
lVMacros.Enabled = on;
|
|
cBRecordDelays.Enabled = on;
|
|
cBStyle.Enabled = on;
|
|
pnlMouseButtons.Visible = !on;
|
|
}
|
|
|
|
[DllImport("user32.dll")]
|
|
private static extern short GetAsyncKeyState(Keys key);
|
|
|
|
private void anyKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (btnRecord.Text == Properties.Resources.StopText)
|
|
{
|
|
int value = WhichKey(e, 0);
|
|
int count = 0;
|
|
foreach (int i in macros)
|
|
{
|
|
if (i == value)
|
|
count++;
|
|
}
|
|
if (macros.Count == 0)
|
|
{
|
|
macros.Add(value);
|
|
lVMacros.Items.Add(((Keys)value).ToString(), 0);
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
}
|
|
else if (count % 2 == 0)
|
|
{
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
macros.Add((int)sw.ElapsedMilliseconds + 300);
|
|
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", sw.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
macros.Add(value);
|
|
lVMacros.Items.Add(((Keys)value).ToString(), 0);
|
|
}
|
|
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
|
|
}
|
|
else if (e.KeyValue == 27)
|
|
Close();
|
|
}
|
|
|
|
private int WhichKey(KeyEventArgs e, int keystate)
|
|
{
|
|
if (keystate == 1)
|
|
{
|
|
if (e.KeyCode == Keys.ShiftKey)
|
|
{
|
|
for (int i = macros.Count - 1; i >= 0; i--)
|
|
if (macros[i] == 160)
|
|
return 160;
|
|
else if (macros[i] == 161)
|
|
return 161;
|
|
}
|
|
else if (e.KeyCode == Keys.ControlKey)
|
|
{
|
|
for (int i = macros.Count - 1; i >= 0; i--)
|
|
if (macros[i] == 162)
|
|
return 162;
|
|
else if (macros[i] == 163)
|
|
return 163;
|
|
}
|
|
else if (e.KeyCode == Keys.Menu)
|
|
{
|
|
for (int i = macros.Count - 1; i >= 0; i--)
|
|
if (macros[i] == 164)
|
|
return 164;
|
|
else if (macros[i] == 165)
|
|
return 165;
|
|
}
|
|
return e.KeyValue;
|
|
}
|
|
else
|
|
if (e.KeyCode == Keys.ShiftKey)
|
|
{
|
|
if (Convert.ToBoolean(GetAsyncKeyState(Keys.LShiftKey)))
|
|
return 160;
|
|
if (Convert.ToBoolean(GetAsyncKeyState(Keys.RShiftKey)))
|
|
return 161;
|
|
}
|
|
else if (e.KeyCode == Keys.ControlKey)
|
|
{
|
|
if (Convert.ToBoolean(GetAsyncKeyState(Keys.LControlKey)))
|
|
return 162;
|
|
if (Convert.ToBoolean(GetAsyncKeyState(Keys.RControlKey)))
|
|
return 163;
|
|
}
|
|
else if (e.KeyCode == Keys.Menu)
|
|
{
|
|
e.Handled = true;
|
|
if (Convert.ToBoolean(GetAsyncKeyState(Keys.LMenu)))
|
|
return 164;
|
|
if (Convert.ToBoolean(GetAsyncKeyState(Keys.RMenu)))
|
|
return 165;
|
|
|
|
}
|
|
return e.KeyValue;
|
|
}
|
|
|
|
private void anyKeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
if (btnRecord.Text == Properties.Resources.StopText && macros.Count != 0)
|
|
{
|
|
int value = WhichKey(e, 1);
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
macros.Add((int)sw.ElapsedMilliseconds + 300);
|
|
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", sw.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
macros.Add(value);
|
|
lVMacros.Items.Add(((Keys)value).ToString(), 1);
|
|
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
|
|
}
|
|
}
|
|
private void anyMouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (btnRecord.Text == Properties.Resources.StopText)
|
|
{
|
|
int value;
|
|
switch (e.Button)
|
|
{
|
|
case System.Windows.Forms.MouseButtons.Left: value = 256; break;
|
|
case System.Windows.Forms.MouseButtons.Right: value = 257; break;
|
|
case System.Windows.Forms.MouseButtons.Middle: value = 258; break;
|
|
case System.Windows.Forms.MouseButtons.XButton1: value = 259; break;
|
|
case System.Windows.Forms.MouseButtons.XButton2: value = 260; break;
|
|
default: value = 0; break;
|
|
}
|
|
if (macros.Count == 0)
|
|
{
|
|
macros.Add(value);
|
|
lVMacros.Items.Add(e.Button.ToString() + " Mouse Button", 0);
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
macros.Add((int)sw.ElapsedMilliseconds + 300);
|
|
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", sw.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
macros.Add(value);
|
|
lVMacros.Items.Add(e.Button.ToString() + " Mouse Button", 0);
|
|
}
|
|
if (e.Button == System.Windows.Forms.MouseButtons.XButton1)
|
|
lVMacros.Items[lVMacros.Items.Count - 1].Text = "4th Mouse Button";
|
|
if (e.Button == System.Windows.Forms.MouseButtons.XButton2)
|
|
lVMacros.Items[lVMacros.Items.Count - 1].Text = "5th Mouse Button";
|
|
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
|
|
}
|
|
}
|
|
|
|
private void anyMouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
if (btnRecord.Text == Properties.Resources.StopText && macros.Count != 0)
|
|
{
|
|
int value;
|
|
switch (e.Button)
|
|
{
|
|
case System.Windows.Forms.MouseButtons.Left: value = 256; break;
|
|
case System.Windows.Forms.MouseButtons.Right: value = 257; break;
|
|
case System.Windows.Forms.MouseButtons.Middle: value = 258; break;
|
|
case System.Windows.Forms.MouseButtons.XButton1: value = 259; break;
|
|
case System.Windows.Forms.MouseButtons.XButton2: value = 260; break;
|
|
default: value = 0; break;
|
|
}
|
|
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
macros.Add((int)sw.ElapsedMilliseconds + 300);
|
|
lVMacros.Items.Add("Wait " + sw.ElapsedMilliseconds + "ms", 2);
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
macros.Add(value);
|
|
lVMacros.Items.Add(e.Button.ToString() + " Mouse Button", 1);
|
|
if (e.Button == System.Windows.Forms.MouseButtons.XButton1)
|
|
lVMacros.Items[lVMacros.Items.Count - 1].Text = "4th Mouse Button";
|
|
if (e.Button == System.Windows.Forms.MouseButtons.XButton2)
|
|
lVMacros.Items[lVMacros.Items.Count - 1].Text = "5th Mouse Button";
|
|
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
|
|
}
|
|
}
|
|
|
|
|
|
public void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (macros.Count > 0)
|
|
{
|
|
kbm.macrostag = macros;
|
|
macronames.Clear();
|
|
foreach (ListViewItem lvi in lVMacros.Items)
|
|
{
|
|
macronames.Add(lvi.Text);
|
|
}
|
|
kbm.macros = macronames;
|
|
string macro = string.Join(", ", macronames.ToArray());
|
|
kbm.lBMacroOn.Visible = true;
|
|
if (cBStyle.SelectedIndex == 1)
|
|
kbm.macrorepeat = true;
|
|
saved = true;
|
|
if (sender != kbm)
|
|
kbm.Close();
|
|
//Close();
|
|
}
|
|
else MessageBox.Show(Properties.Resources.NoMacroRecorded, "DS4Windows", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
|
|
|
|
private void btnSaveP_Click(object sender, EventArgs e)
|
|
{
|
|
if (macros.Count > 0)
|
|
{
|
|
Stream stream;
|
|
Console.WriteLine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName);
|
|
Console.WriteLine(Global.appdatapath);
|
|
//string path;
|
|
if (Global.appdatapath == Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName)
|
|
savePresets.InitialDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + @"\Macros\";
|
|
else
|
|
savePresets.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + @"\Macros\";
|
|
if (!Directory.Exists(savePresets.InitialDirectory))
|
|
{
|
|
Directory.CreateDirectory(savePresets.InitialDirectory);
|
|
//savePresets.InitialDirectory = path;
|
|
}
|
|
Console.WriteLine(savePresets.InitialDirectory);
|
|
if (savePresets.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
if ((stream = savePresets.OpenFile()) != null)
|
|
{
|
|
string macro = string.Join("/", macros.ToArray());
|
|
StreamWriter sw = new StreamWriter(stream);
|
|
sw.Write(macro);
|
|
sw.Close();
|
|
//stream.Close();
|
|
}
|
|
}
|
|
else MessageBox.Show(Properties.Resources.NoMacroRecorded, "DS4Windows", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
|
|
private void btnLoadP_Click(object sender, EventArgs e)
|
|
{
|
|
if (Global.appdatapath == Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName)
|
|
openPresets.InitialDirectory = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + @"\Macros\";
|
|
else
|
|
openPresets.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + @"\Macros\";
|
|
if (openPresets.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
string file = openPresets.FileName;
|
|
macros.Clear();
|
|
lVMacros.Items.Clear();
|
|
StreamReader sr = new StreamReader(file);
|
|
string[] macs = File.ReadAllText(file).Split('/');
|
|
int temp;
|
|
foreach (string s in macs)
|
|
{
|
|
if (int.TryParse(s, out temp))
|
|
macros.Add(temp);
|
|
}
|
|
LoadMacro();
|
|
sr.Close();
|
|
}
|
|
}
|
|
|
|
private void lVMacros_MouseHover(object sender, EventArgs e)
|
|
{
|
|
lVMacros.Focus();
|
|
}
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
saved = true;
|
|
Close();
|
|
}
|
|
|
|
private void btn4th_Click(object sender, EventArgs e)
|
|
{
|
|
int value = 259;
|
|
if (btn4th.Text.Contains(Properties.Resources.DownText))
|
|
{
|
|
if (macros.Count == 0)
|
|
{
|
|
macros.Add(value);
|
|
lVMacros.Items.Add("4th Mouse Button", 0);
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
macros.Add((int)sw.ElapsedMilliseconds + 300);
|
|
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", sw.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
macros.Add(value);
|
|
lVMacros.Items.Add("4th Mouse Button", 0);
|
|
}
|
|
btn4th.Text = Properties.Resources.FourthMouseUp;
|
|
}
|
|
else
|
|
{
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
macros.Add((int)sw.ElapsedMilliseconds + 300);
|
|
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", sw.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
macros.Add(value);
|
|
lVMacros.Items.Add("4th Mouse Button", 1);
|
|
btn4th.Text = Properties.Resources.FourthMouseDown;
|
|
}
|
|
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
|
|
}
|
|
|
|
private void btn5th_Click(object sender, EventArgs e)
|
|
{
|
|
int value = 260;
|
|
if (btn5th.Text.Contains(Properties.Resources.DownText))
|
|
{
|
|
if (macros.Count == 0)
|
|
{
|
|
macros.Add(value);
|
|
lVMacros.Items.Add("5th Mouse Button", 0);
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
macros.Add((int)sw.ElapsedMilliseconds + 300);
|
|
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", sw.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
macros.Add(value);
|
|
lVMacros.Items.Add("5th Mouse Button", 0);
|
|
}
|
|
btn5th.Text = Properties.Resources.FifthMouseUp;
|
|
}
|
|
else
|
|
{
|
|
if (cBRecordDelays.Checked)
|
|
{
|
|
macros.Add((int)sw.ElapsedMilliseconds + 300);
|
|
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", sw.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
|
|
sw.Reset();
|
|
sw.Start();
|
|
}
|
|
macros.Add(value);
|
|
lVMacros.Items.Add("5th Mouse Button", 1);
|
|
btn5th.Text = Properties.Resources.FifthMouseDown;
|
|
}
|
|
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
|
|
}
|
|
|
|
void LoadMacro()
|
|
{
|
|
|
|
if (macros.Count > 0)
|
|
{
|
|
bool[] keydown = new bool[286];
|
|
foreach (int i in macros)
|
|
{
|
|
if (i >= 300) //ints over 300 used to delay
|
|
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", (i - 300).ToString()).Replace("*ms*", "ms"), 2);
|
|
else if (!keydown[i])
|
|
{
|
|
//anything above 255 is not a keyvalue
|
|
if (i == 256) lVMacros.Items.Add("Left Mouse Button", 0);
|
|
else if (i == 257) lVMacros.Items.Add("Right Mouse Button", 0);
|
|
else if (i == 258) lVMacros.Items.Add("Middle Mouse Button", 0);
|
|
else if (i == 259) lVMacros.Items.Add("4th Mouse Button", 0);
|
|
else if (i == 260) lVMacros.Items.Add("5th Mouse Button", 0);
|
|
else if (i == 261) lVMacros.Items.Add("A Button", 0);
|
|
else if (i == 262) lVMacros.Items.Add("B Button", 0);
|
|
else if (i == 263) lVMacros.Items.Add("X Button", 0);
|
|
else if (i == 264) lVMacros.Items.Add("Y Button", 0);
|
|
else if (i == 265) lVMacros.Items.Add("Start", 0);
|
|
else if (i == 266) lVMacros.Items.Add("Back", 0);
|
|
else if (i == 267) lVMacros.Items.Add("Up Button", 0);
|
|
else if (i == 268) lVMacros.Items.Add("Down Button", 0);
|
|
else if (i == 269) lVMacros.Items.Add("Left Button", 0);
|
|
else if (i == 270) lVMacros.Items.Add("Right Button", 0);
|
|
else if (i == 271) lVMacros.Items.Add("Guide", 0);
|
|
else if (i == 272) lVMacros.Items.Add("Left Bumper", 0);
|
|
else if (i == 273) lVMacros.Items.Add("Right Bumper", 0);
|
|
else if (i == 274) lVMacros.Items.Add("Left Trigger", 0);
|
|
else if (i == 275) lVMacros.Items.Add("Right Trigger", 0);
|
|
else if (i == 276) lVMacros.Items.Add("Left Stick", 0);
|
|
else if (i == 277) lVMacros.Items.Add("Right Stick", 0);
|
|
else if (i == 278) lVMacros.Items.Add("LS Right", 0);
|
|
else if (i == 279) lVMacros.Items.Add("LS Left", 0);
|
|
else if (i == 280) lVMacros.Items.Add("LS Down", 0);
|
|
else if (i == 281) lVMacros.Items.Add("LS Up", 0);
|
|
else if (i == 282) lVMacros.Items.Add("RS Right", 0);
|
|
else if (i == 283) lVMacros.Items.Add("RS Left", 0);
|
|
else if (i == 284) lVMacros.Items.Add("RS Down", 0);
|
|
else if (i == 285) lVMacros.Items.Add("RS Up", 0);
|
|
else lVMacros.Items.Add(((Keys)i).ToString(), 0);
|
|
keydown[i] = true;
|
|
}
|
|
else
|
|
{
|
|
if (i == 256) lVMacros.Items.Add("Left Mouse Button", 1);
|
|
else if (i == 257) lVMacros.Items.Add("Right Mouse Button", 1);
|
|
else if (i == 258) lVMacros.Items.Add("Middle Mouse Button", 1);
|
|
else if (i == 259) lVMacros.Items.Add("4th Mouse Button", 1);
|
|
else if (i == 260) lVMacros.Items.Add("5th Mouse Button", 1);
|
|
else if (i == 261) lVMacros.Items.Add("A Button", 1);
|
|
else if (i == 262) lVMacros.Items.Add("B Button", 1);
|
|
else if (i == 263) lVMacros.Items.Add("X Button", 1);
|
|
else if (i == 264) lVMacros.Items.Add("Y Button", 1);
|
|
else if (i == 265) lVMacros.Items.Add("Start", 1);
|
|
else if (i == 266) lVMacros.Items.Add("Back", 1);
|
|
else if (i == 267) lVMacros.Items.Add("Up Button", 1);
|
|
else if (i == 268) lVMacros.Items.Add("Down Button", 1);
|
|
else if (i == 269) lVMacros.Items.Add("Left Button", 1);
|
|
else if (i == 270) lVMacros.Items.Add("Right Button", 1);
|
|
else if (i == 271) lVMacros.Items.Add("Guide", 1);
|
|
else if (i == 272) lVMacros.Items.Add("Left Bumper", 1);
|
|
else if (i == 273) lVMacros.Items.Add("Right Bumper", 1);
|
|
else if (i == 274) lVMacros.Items.Add("Left Trigger", 1);
|
|
else if (i == 275) lVMacros.Items.Add("Right Trigger", 1);
|
|
else if (i == 276) lVMacros.Items.Add("Left Stick", 1);
|
|
else if (i == 277) lVMacros.Items.Add("Right Stick", 1);
|
|
else if (i == 278) lVMacros.Items.Add("LS Right", 1);
|
|
else if (i == 279) lVMacros.Items.Add("LS Left", 1);
|
|
else if (i == 280) lVMacros.Items.Add("LS Down", 1);
|
|
else if (i == 281) lVMacros.Items.Add("LS Up", 1);
|
|
else if (i == 282) lVMacros.Items.Add("RS Right", 1);
|
|
else if (i == 283) lVMacros.Items.Add("RS Left", 1);
|
|
else if (i == 284) lVMacros.Items.Add("RS Down", 1);
|
|
else if (i == 285) lVMacros.Items.Add("RS Up", 1);
|
|
else lVMacros.Items.Add(((Keys)i).ToString(), 1);
|
|
keydown[i] = false;
|
|
}
|
|
}
|
|
for (ushort i = 0; i < keydown.Length; i++)
|
|
{
|
|
if (keydown[i])
|
|
{
|
|
if (i == 256) lVMacros.Items.Add("Left Mouse Button", 1);
|
|
else if (i == 257) lVMacros.Items.Add("Right Mouse Button", 1);
|
|
else if (i == 258) lVMacros.Items.Add("Middle Mouse Button", 1);
|
|
else if (i == 259) lVMacros.Items.Add("4th Mouse Button", 1);
|
|
else if (i == 260) lVMacros.Items.Add("5th Mouse Button", 1);
|
|
else if (i == 261) lVMacros.Items.Add("A Button", 1);
|
|
else if (i == 262) lVMacros.Items.Add("B Button", 1);
|
|
else if (i == 263) lVMacros.Items.Add("X Button", 1);
|
|
else if (i == 264) lVMacros.Items.Add("Y Button", 1);
|
|
else if (i == 265) lVMacros.Items.Add("Start", 1);
|
|
else if (i == 266) lVMacros.Items.Add("Back", 1);
|
|
else if (i == 267) lVMacros.Items.Add("Up Button", 1);
|
|
else if (i == 268) lVMacros.Items.Add("Down Button", 1);
|
|
else if (i == 269) lVMacros.Items.Add("Left Button", 1);
|
|
else if (i == 270) lVMacros.Items.Add("Right Button", 1);
|
|
else if (i == 271) lVMacros.Items.Add("Guide", 1);
|
|
else if (i == 272) lVMacros.Items.Add("Left Bumper", 1);
|
|
else if (i == 273) lVMacros.Items.Add("Right Bumper", 1);
|
|
else if (i == 274) lVMacros.Items.Add("Left Trigger", 1);
|
|
else if (i == 275) lVMacros.Items.Add("Right Trigger", 1);
|
|
else if (i == 276) lVMacros.Items.Add("Left Stick", 1);
|
|
else if (i == 277) lVMacros.Items.Add("Right Stick", 1);
|
|
else if (i == 278) lVMacros.Items.Add("LS Right", 1);
|
|
else if (i == 279) lVMacros.Items.Add("LS Left", 1);
|
|
else if (i == 280) lVMacros.Items.Add("LS Down", 1);
|
|
else if (i == 281) lVMacros.Items.Add("LS Up", 1);
|
|
else if (i == 282) lVMacros.Items.Add("RS Right", 1);
|
|
else if (i == 283) lVMacros.Items.Add("RS Left", 1);
|
|
else if (i == 284) lVMacros.Items.Add("RS Down", 1);
|
|
else if (i == 285) lVMacros.Items.Add("RS Up", 1);
|
|
else lVMacros.Items.Add(((Keys)i).ToString(), 1);
|
|
macros.Add(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void RecordBox_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (!saved && macros.Count > 0)
|
|
if (MessageBox.Show(Properties.Resources.SaveRecordedMacro, "DS4Windows", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
|
|
btnSave_Click(null, null);
|
|
}
|
|
|
|
protected override bool IsInputKey(Keys keyData)
|
|
{
|
|
switch (keyData)
|
|
{
|
|
case Keys.Right:
|
|
case Keys.Left:
|
|
case Keys.Up:
|
|
case Keys.Down:
|
|
case Keys.Tab:
|
|
case Keys.MediaPlayPause:
|
|
case Keys.MediaPreviousTrack:
|
|
case Keys.MediaNextTrack:
|
|
return true;
|
|
case Keys.Shift | Keys.Right:
|
|
case Keys.Shift | Keys.Left:
|
|
case Keys.Shift | Keys.Up:
|
|
case Keys.Shift | Keys.Down:
|
|
case Keys.Shift | Keys.Tab:
|
|
case Keys.Shift | Keys.MediaPlayPause:
|
|
case Keys.Shift | Keys.MediaPreviousTrack:
|
|
case Keys.Shift | Keys.MediaNextTrack:
|
|
return true;
|
|
}
|
|
return base.IsInputKey(keyData);
|
|
}
|
|
protected override void OnKeyDown(KeyEventArgs e)
|
|
{
|
|
base.OnKeyDown(e);
|
|
switch (e.KeyCode)
|
|
{
|
|
case Keys.Left:
|
|
case Keys.Right:
|
|
case Keys.Up:
|
|
case Keys.Down:
|
|
case Keys.Tab:
|
|
case Keys.MediaPlayPause:
|
|
case Keys.MediaPreviousTrack:
|
|
case Keys.MediaNextTrack:
|
|
if (e.Shift)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
private int selection;
|
|
private void lVMacros_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
{
|
|
if (lVMacros.SelectedIndices[0] >= 0 && lVMacros.SelectedItems[0].ImageIndex == 2)
|
|
{
|
|
TextBox tb = new TextBox();
|
|
tb.KeyDown += nud_KeyDown;
|
|
tb.LostFocus += nud_LostFocus;
|
|
selection = lVMacros.SelectedIndices[0];
|
|
Controls.Add(tb);
|
|
tb.Location = new Point(lVMacros.Location.X + lVMacros.SelectedItems[0].Position.X, lVMacros.Location.Y + lVMacros.SelectedItems[0].Position.Y);
|
|
tb.BringToFront();
|
|
lVMacros.MouseHover -= lVMacros_MouseHover;
|
|
tb.TextChanged += tb_TextChanged;
|
|
tb.Focus();
|
|
}
|
|
}
|
|
|
|
void tb_TextChanged(object sender, EventArgs e)
|
|
{
|
|
TextBox tb = (TextBox)sender;
|
|
for (int i = tb.Text.Length - 1; i >= 0; i--)
|
|
if (!Char.IsDigit(tb.Text[i]))
|
|
tb.Text = tb.Text.Remove(i, 1);
|
|
}
|
|
|
|
void nud_LostFocus(object sender, EventArgs e)
|
|
{
|
|
TextBox tb = (TextBox)sender;
|
|
int i;
|
|
if (!string.IsNullOrEmpty(tb.Text) && int.TryParse(tb.Text, out i))
|
|
{
|
|
lVMacros.Items[selection] = new ListViewItem(Properties.Resources.WaitMS.Replace("*number*", (tb.Text)).Replace("*ms*", "ms"), 2);
|
|
macros[selection] = i + 300;
|
|
saved = false;
|
|
}
|
|
Controls.Remove(tb);
|
|
lVMacros.MouseHover += lVMacros_MouseHover;
|
|
}
|
|
|
|
void nud_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
TextBox tb = (TextBox)sender;
|
|
if (e.KeyCode == Keys.Enter && !string.IsNullOrEmpty(tb.Text))
|
|
{
|
|
int i;
|
|
if (int.TryParse(tb.Text, out i))
|
|
{
|
|
lVMacros.Items[selection] = new ListViewItem(Properties.Resources.WaitMS.Replace("*number*", (tb.Text)).Replace("*ms*", "ms"), 2);
|
|
macros[selection] = i + 300;
|
|
saved = false;
|
|
Controls.Remove(tb);
|
|
lVMacros.MouseHover += lVMacros_MouseHover;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|