private void ProgressUpdateMassSet(bool isPressed, double progress) { var prg = new ProgressUpdate(); foreach (var key in config.keys) { if (key.Type == "JoystickKey" || key.Type == "Tactile") { var tac = new ProgressUpdate.Types.TactileUpdate(); tac.Id = 0; tac.Fired = false; // isPressed; tac.Progress = progress; prg.Tactile.Add(tac); } if (key.Type == "Joystick") { var joy = new ProgressUpdate.Types.JoystickUpdate(); joy.Id = 0; joy.Intensity = progress; prg.Joystick.Add(joy); } } client.SendProgressUpdate(prg); }
//Handle Stream of Reports public async Task StreamReport() { UInt32 jid; //Start Stream Report try { //Prepare a Stream Report for usage using (var call = client.StreamReport(new StreamRequest())) { var responseStream = call.ResponseStream; //Loop the stream, consuming data while (await responseStream.MoveNext()) { ProgressUpdate prg = new ProgressUpdate(); bool isProgressUpdated = false; Report report = responseStream.Current; //Ignore report if window isn't focused //Console.WriteLine(report); if (Form1.GetInstance().processHandleWindow != w32.GetForegroundWindow()) { Form1.GetInstance().Text = "[" + Form1.GetInstance().GetProcessName() + "] GoBeam v" + Application.ProductVersion; //Form1.GetInstance().SetStatus("Window not visible"); //continue; } else { Form1.GetInstance().Text = ">[" + Form1.GetInstance().GetProcessName() + "]< GoBeam v" + Application.ProductVersion; //Form1.GetInstance().SetStatus(""); } //iterate keymap foreach (var key in Form1.config.keys) { if (!key.IsPressed && key.progress > 0) { key.progress -= 0.05; //Write an eventual cooldown of keys var tac = new ProgressUpdate.Types.TactileUpdate(); tac.Id = (UInt32)key.Index; tac.Fired = false; tac.Progress = key.progress; prg.Tactile.Add(tac); isProgressUpdated = true; } bool isAnyButtonPressed = false; //iterate touches foreach (var touch in report.Tactile) { if (key.Index != touch.Id) continue; if (touch.Holding > 0 || touch.PressFrequency > 0 || touch.ReleaseFrequency > 0) { //Console.WriteLine(touch.Id + ": " + touch.Holding + ", "+ touch.PressFrequency+ "," + touch.ReleaseFrequency); } //Press or release key based on report if ((touch.PressFrequency != 0 && !key.IsPressed) || (touch.ReleaseFrequency != 0 && key.IsPressed)) { key.IsPressed = !key.IsPressed; if (key.IsPressed) { key.IdleTime = 0; isAnyButtonPressed = true; Form1.SetLeftProgress(1); //If the key hasn't been pressed in some time, re-do halo effect if (key.progress == 0.0) key.progress = 1.0; } if (key.Type == "Tactile") { //Focus only required for keyboard if (Form1.GetInstance().processHandleWindow != w32.GetForegroundWindow()) continue; //Console.WriteLine("TactileKey" + touch.Id + " ("+key.KeyName+"), " + key.IsPressed); w32.keybd_event(key.KeyCode, 0, (key.IsPressed) ? 0 : w32.KEYEVENTF_KEYUP, 0); } else if (key.Type == "JoystickKey") { //It gets here if (key.joystickIndex < 1) { continue; } //Console.WriteLine("JoystickKey " + touch.Id + " (J: "+key.joystickIndex+", "+key.KeyName+"), " + key.IsPressed); foreach (var jKey in Form1.config.keys) { if (jKey.joystickIndex == key.joystickIndex && jKey.KeyCode == key.KeyCode) { //Find joystick, since after I made multiple joysticks available my old code got borked vJoy joystick = null; foreach (var joyKey in Form1.config.keys) { if (joyKey.joystick != null && joyKey.joystickIndex == jKey.joystickIndex && joyKey.IsEnabled) { joystick = joyKey.joystick; break; } } if (joystick == null) { MessageBox.Show("Invalid joystick passed for key" + jKey.Index); } joystick.SetBtn(key.IsPressed, (UInt32)key.joystickIndex, key.KeyCode); break; } } // w32.keybd_event(key.KeyCode, 0, (key.IsPressed) ? 0 : w32.KEYEVENTF_KEYUP, 0); } var tac = new ProgressUpdate.Types.TactileUpdate(); tac.Id = (UInt32)key.Index; tac.Fired = false; if (key.progress == 1.0) tac.Fired = true; tac.Progress = key.progress; prg.Tactile.Add(tac); isProgressUpdated = true; } } if (!isAnyButtonPressed) Form1.SetLeftProgress(0); foreach (var joy in report.Joystick) { if (key.Index != joy.Id) continue; if (key.joystick == null) continue; if (!key.IsEnabled) continue; jid = (UInt32)key.KeyCode; //Console.WriteLine("joy " + joy.Id + ": " + joy.CoordMean.X + ", " + joy.CoordMean.Y); if ((!double.Equals(joy.CoordMean.X, double.NaN) && !key.IsPressed) || (!double.Equals(joy.CoordMean.Y, double.NaN) && !key.IsPressed) || (double.Equals(joy.CoordMean.X, double.NaN) && key.IsPressed) || ( double.Equals(joy.CoordMean.Y, double.NaN) && key.IsPressed)) { //Form1.GetInstance().SetStatus("Joystick"); key.IsPressed = !key.IsPressed; var ju = new ProgressUpdate.Types.JoystickUpdate(); ju.Id = jid; ju.Intensity = (double)((key.IsPressed) ? 1.0 : 0.0); prg.Joystick.Add(ju); isProgressUpdated = true; } //Console.Write(joy.CoordMean.X + "," + joy.CoordMean.Y); //Form1.JoystickIdle(key.joystick, (byte)jid, (int)maxval); if (double.Equals(joy.CoordMean.X, double.NaN) && double.Equals(joy.CoordMean.Y, double.NaN)) { if (key.IdleTime < 3) key.IdleTime++; if (key.IdleTime > 2) { //Console.WriteLine("idle"); //Form1.GetInstance().SetStatus("Idle"); key.joystick.ResetVJD(jid); Form1.JoystickIdle(key.joystick, (byte)jid, (int)maxval); Form1.SetRightProgress(0); key.joystick.SetAxis((int)(maxval * 0.5f), jid, HID_USAGES.HID_USAGE_X); key.joystick.SetAxis((int)(maxval * 0.5f), jid, HID_USAGES.HID_USAGE_Y); } } else { Form1.SetRightProgress(1); key.IdleTime = 0; if (double.Equals(joy.CoordMean.X,double.NaN)) { key.joystick.SetAxis((int)(maxval * 0.5f), jid, HID_USAGES.HID_USAGE_X); } else { //Console.Write(" X: " + ", " + joy.CoordMean.X); key.joystick.SetAxis((int)(maxval * ((joy.CoordMean.X + 1.0f) / 2.0f)), jid, HID_USAGES.HID_USAGE_X); } if (double.Equals(joy.CoordMean.Y, double.NaN)) { key.joystick.SetAxis((int)(maxval * 0.5f), jid, HID_USAGES.HID_USAGE_Y); } else { //Console.Write(" Y: " + joy.CoordMean.Y); key.joystick.SetAxis((int)(maxval * ((joy.CoordMean.Y + 1.0f) / 2.0f)), jid, HID_USAGES.HID_USAGE_Y); } // Console.WriteLine(key.joystick); } } } if (isProgressUpdated) { //Console.WriteLine("Progress Update"); SendProgressUpdate(prg); } } } } catch (RpcException e) { Form1.GetInstance().DisconnectRPC(); MessageBox.Show("RPC Failed: " + e.Message); throw; } }