コード例 #1
0
ファイル: SettingsForm.cs プロジェクト: TinyThor/PS3BluMote
        private void remote_ButtonDown(object sender, PS3Remote.ButtonData e)
        {
            if (DebugLog.isLogging)
            {
                DebugLog.write("Button down: " + e.button.ToString());
            }

            ButtonMapping mapping = buttonMappings[(int)e.button];

            if (mapping.repeat)
            {
                keyboard.sendKeysDown(mapping.keysMapped);
                keyboard.releaseLastKeys();

                if (DebugLog.isLogging)
                {
                    DebugLog.write("Keys repeat send on : { " + String.Join(",", mapping.keysMapped.ToArray()) + " }");
                }

                timerRepeat.Enabled = true;
                return;
            }

            keyboard.sendKeysDown(mapping.keysMapped);

            if (DebugLog.isLogging)
            {
                DebugLog.write("Keys down: { " + String.Join(",", mapping.keysMapped.ToArray()) + " }");
            }
        }
コード例 #2
0
ファイル: SettingsForm.cs プロジェクト: TinyThor/PS3BluMote
        private void remote_ButtonReleased(object sender, PS3Remote.ButtonData e)
        {
            if (DebugLog.isLogging)
            {
                DebugLog.write("Button released: " + e.button.ToString());
            }

            if (timerRepeat.Enabled)
            {
                if (DebugLog.isLogging)
                {
                    DebugLog.write("Keys repeat send off: { " + String.Join(",", keyboard.lastKeysDown.ToArray()) + " }");
                }

                timerRepeat.Enabled = false;
                return;
            }

            if (DebugLog.isLogging && this.keyboard.lastKeysDown != null)
            {
                DebugLog.write("Keys up: { " + String.Join(",", keyboard.lastKeysDown.ToArray()) + " }");
            }

            keyboard.releaseLastKeys();
        }
コード例 #3
0
        public static List <string> GetNearbyRemoteAddresses(TimeSpan timeout)
        {
            List <string> result = new List <string>();

            try
            {
                BluetoothClient cli = new BluetoothClient();
                if (timeout != TimeSpan.Zero)
                {
                    cli.InquiryLength = timeout;
                }
                var devs = cli.DiscoverDevices().ToList();
                foreach (BluetoothDeviceInfo dev in devs)
                {
                    if (dev.DeviceName.ToLower().Contains("bd remote control"))
                    {
                        if (RemoteBtState(null, dev) == RemoteBtStates.Awake)
                        {
                            string candidate = FormatBtAddress(null, dev.DeviceAddress, "N");
                            if (!result.Contains(candidate))
                            {
                                result.Add(candidate);
                            }
                        }
                    }
                }
            }
            catch
            {
                DebugLog.write("BTUtils.GetNearbyRemoteAddresses Failed");
            }
            return(result);
        }
コード例 #4
0
ファイル: PS3Remote.cs プロジェクト: TinyThor/PS3BluMote
        private void timerHibernation_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                if (hidRemote != null)
                {
                    if (DebugLog.isLogging)
                    {
                        DebugLog.write("Attempting to hibernate remote");
                    }

                    DeviceHelper.SetDeviceEnabled(new Guid(Properties.Settings.Default.ClassGuid), @Properties.Settings.Default.devicePath, false);
                    System.Threading.Thread.Sleep(3000);
                    DeviceHelper.SetDeviceEnabled(new Guid(Properties.Settings.Default.ClassGuid), @Properties.Settings.Default.devicePath, true);
                }
            }
            catch (Exception ex)
            {
                if (DebugLog.isLogging)
                {
                    DebugLog.write("Unable to hibernate remote:" + ex.Message);
                }
                timerFixRemote.Enabled   = true;
                timerFindRemote.Enabled  = false;
                timerHibernation.Enabled = false;
                return;
            }

            timerFindRemote.Enabled  = true;
            timerHibernation.Enabled = false;
        }
コード例 #5
0
ファイル: SettingsForm.cs プロジェクト: TinyThor/PS3BluMote
        private void remote_BatteryLifeChanged(object sender, EventArgs e)
        {
            notifyIcon.Text = "PS3BluMote: Connected + (Battery: " + remote.getBatteryLife.ToString() + "%).";

            if (DebugLog.isLogging)
            {
                DebugLog.write("Battery life: " + remote.getBatteryLife.ToString() + "%");
            }
        }
コード例 #6
0
ファイル: SettingsForm.cs プロジェクト: TinyThor/PS3BluMote
        private void remote_Hibernated(object sender, EventArgs e)
        {
            if (DebugLog.isLogging)
            {
                DebugLog.write("Remote Hibernated");
            }

            notifyIcon.Text = "PS3BluMote: Hibernated (Battery: " + remote.getBatteryLifeString() + ").";
            notifyIcon.Icon = Properties.Resources.Icon_Hibernated;
        }
コード例 #7
0
ファイル: SettingsForm.cs プロジェクト: TinyThor/PS3BluMote
        private void remote_Disconnected(object sender, EventArgs e)
        {
            if (DebugLog.isLogging)
            {
                DebugLog.write("Remote disconnected");
            }

            notifyIcon.Text = "PS3BluMote: Disconnected.";
            notifyIcon.Icon = Properties.Resources.Icon_Disconnected;
        }
コード例 #8
0
ファイル: RegUtils.cs プロジェクト: TinyThor/PS3BluMote
 public static void SetDevDisconnectedSound(string sound)
 {
     try
     {
         Registry.SetValue(@"HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\DeviceDisconnect\.Current", "", sound);
     }
     catch
     {
         DebugLog.write("RegUtils.SetDevDisconnectedSound Failed");
     }
 }
コード例 #9
0
ファイル: RegUtils.cs プロジェクト: TinyThor/PS3BluMote
 public static string GetDevDisconnectedSound()
 {
     try
     {
         return((string)Registry.GetValue(@"HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\DeviceDisconnect\.Current", "", ""));
     }
     catch
     {
         DebugLog.write("RegUtils.GetDevConnectedSound Failed");
         return(null);
     }
 }
コード例 #10
0
        private static List <string> FromBT()
        {
            List <string> btResult;

            btResult = BTUtils.GetNearbyRemoteAddresses(TimeSpan.FromSeconds(1));
            if (btResult.Count == 0)
            {
                btResult = BTUtils.GetNearbyRemoteAddresses(TimeSpan.Zero);
            }
            for (int i = 0; i < btResult.Count; i++)
            {
                btResult[i] = BTUtils.FormatBtAddress(btResult[i], null, "N");
                DebugLog.write("FindBTAddress.FromBT will return " + btResult[i]);
            }
            return(btResult);
        }
コード例 #11
0
        public static List <string> Find(string pid, string vid)
        {
            List <string> result = new List <string>();

            List <string> regResult = FromReg(pid, vid);

            if (regResult.Count == 1)
            {
                result.Add(regResult[0]);
                DebugLog.write("FindBtAddress.Find returns regResult since we got only one match");
            }
            else
            {
                DebugLog.write("FindBtAddress.Find will do a BT Search");
                List <string> btResult = FromBT();

                if (btResult.Count == 0)
                {
                    return(regResult);
                }
                else if (regResult.Count > 0)
                {
                    foreach (string res in regResult)
                    {
                        if (btResult.Contains(res))
                        {
                            if (!result.Contains(res))
                            {
                                result.Add(res);
                            }
                        }
                    }
                }
                else
                {
                    foreach (string res in btResult)
                    {
                        result.Add(res);
                    }
                }
            }
            return(result);
        }
コード例 #12
0
ファイル: PS3Remote.cs プロジェクト: stalkervr/PS3BluMote
        private void timerFindRemote_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (hidRemote == null)
            {
                if (DebugLog.isLogging)
                {
                    DebugLog.write("Searching for remote");
                }

                IEnumerator <HidDevice> devices = HidDevices.Enumerate(vendorId, productId).GetEnumerator();

                if (devices.MoveNext())
                {
                    hidRemote = devices.Current;
                }

                if (hidRemote != null)
                {
                    if (DebugLog.isLogging)
                    {
                        DebugLog.write("Remote found");
                    }

                    hidRemote.OpenDevice();

                    if (Connected != null)
                    {
                        Connected(this, new EventArgs());
                    }

                    hidRemote.Read(readButtonData);

                    timerFindRemote.Enabled = false;
                }
            }
            else
            {
                timerFindRemote.Enabled = false;
            }
        }
コード例 #13
0
        private void remote_ButtonReleased(object sender, PS3Remote.ButtonEventArgs e)
        {
            if (DebugLog.isLogging)
            {
                DebugLog.write("Button released: " + e.button.ToString());
            }

            if (timerRepeat.Enabled)
            {
                //if (DebugLog.isLogging) DebugLog.write("Keys repeat send off: { " + String.Join(",", keyboard.lastKeysDown.ToArray()) + " }");

                timerRepeat.Enabled = false;
                return;
            }

            switch (e.button)
            {
            //case PS3Remote.Button.Arrow_Up:
            //    y -= increment;
            //    break;
            //case PS3Remote.Button.Arrow_Down:
            //    y += increment;
            //    break;
            //case PS3Remote.Button.Arrow_Left:
            //    x -= increment;
            //    break;
            //case PS3Remote.Button.Arrow_Right:
            //    x += increment;
            //    break;
            case PS3Remote.Button.Enter:
                MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftUp);
                return;

            case PS3Remote.Button.PopUp_Menu:
                MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightUp);
                return;
            }
        }
コード例 #14
0
        public static void HibernatePS3Remote(bool checkBefore, string btAddress, BluetoothDeviceInfo dev)
        {
            BluetoothDeviceInfo device;

            if (dev == null && btAddress != null)
            {
                string addr = FormatBtAddress(btAddress, null, "N");
                if (addr.Length > 0)
                {
                    device = new BluetoothDeviceInfo(BluetoothAddress.Parse(btAddress));
                }
                else
                {
                    device = null;
                }
            }
            else if (dev != null)
            {
                device = dev;
            }
            else
            {
                device = null;
            }

            if (device != null)
            {
                if ((checkBefore && RemoteBtState(null, device) == RemoteBtStates.Awake) || !checkBefore)
                {
                    SetHIDServiceState(false, btAddress, device);
                    SetHIDServiceState(true, btAddress, device);
                }
            }
            else
            {
                DebugLog.write("BTUtils.HibernatePS3Remote can't create BluetoothDeviceInfo");
            }
        }
コード例 #15
0
ファイル: PS3Remote.cs プロジェクト: TinyThor/PS3BluMote
        private void timerFixRemote_Elapsed(object sender, ElapsedEventArgs e)
        {
            DebugLog.write("Enable remote as a fix");

            try
            {
                if (hidRemote != null)
                {
                    DeviceHelper.SetDeviceEnabled(new Guid(Properties.Settings.Default.ClassGuid), @Properties.Settings.Default.devicePath, true);
                }
            }
            catch (Exception ex)
            {
                if (DebugLog.isLogging)
                {
                    DebugLog.write("Unable to hibernate remote:" + ex.Message);
                }
                timerFixRemote.Enabled = true;
            }

            timerFindRemote.Enabled  = true;
            timerHibernation.Enabled = false;
            timerFixRemote.Enabled   = false;
        }
コード例 #16
0
        private static List <string> FromReg(string pid, string vid)
        {
            List <string>      result = new List <string>();
            List <RegistryKey> regResult;

            try
            {
                string regFilter;
                if (vid.ToLower().Contains("x"))
                {
                    regFilter = vid.Substring(2);
                }
                else
                {
                    regFilter = vid;
                }
                if (pid.ToLower().Contains("x"))
                {
                    regFilter += "_PID&" + pid.Substring(2);
                }
                else
                {
                    regFilter += "_PID&" + pid;
                }

                regResult = RegUtils.GetKeys(Registry.LocalMachine, regFilter, "Bluetooth_UniqueID");
                foreach (RegistryKey k in regResult)
                {
                    try
                    {
                        string v = (string)k.GetValue("Bluetooth_UniqueID");
                        if (v.Length != 0 && v.Contains("#") && v.Contains("_") && (v.IndexOf("_") - v.IndexOf("#")) == 13)
                        {
                            v = v.Substring(v.IndexOf("#") + 1, 12);
                            v = BTUtils.FormatBtAddress(v, null, "N");
                            if (v != "")
                            {
                                if (!result.Contains(v))
                                {
                                    DebugLog.write("FindBTAddress.FromReg will return " + v);
                                    result.Add(v);
                                }
                            }
                            else
                            {
                                DebugLog.write("FindBTAddress.FromReg parsing returned the empty String (" + (string)k.GetValue("Bluetooth_UniqueID") + ")");
                            }
                        }
                    }
                    catch
                    {
                        try
                        {
                            DebugLog.write("FindBTAddress.FromReg Failed while parsing" + k.Name);
                        }
                        catch
                        {
                            DebugLog.write("FindBTAddress.FromReg Failed while parsing some key ..");
                        }
                    }
                }
                return(result);
            }
            catch
            {
                DebugLog.write("FindBTAddress.FromReg Failed");
                return(result);
            }
        }
コード例 #17
0
        private void remote_ButtonDown(object sender, PS3Remote.ButtonEventArgs e)
        {
            if (DebugLog.isLogging)
            {
                DebugLog.write("Button down: " + e.button.ToString());
            }

            int y = 0;
            int x = 0;

            switch (e.button)
            {
            case PS3Remote.Button.Arrow_Up:
                y -= increment;
                break;

            case PS3Remote.Button.Arrow_Down:
                y += increment;
                break;

            case PS3Remote.Button.Arrow_Left:
                x -= increment;
                break;

            case PS3Remote.Button.Arrow_Right:
                x += increment;
                break;

            case PS3Remote.Button.R1:
                increment++;
                if (increment >= 100)
                {
                    increment = 5;
                }
                break;

            case PS3Remote.Button.L1:
                increment--;
                if (increment <= 0)
                {
                    increment = 5;
                }
                break;

            case PS3Remote.Button.Enter:
                MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftDown);
                return;

            case PS3Remote.Button.PopUp_Menu:
                MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.RightDown);
                return;
            }

            lastButton = e.button;

            if (x != 0 || y != 0)
            {
                //keyboard.sendKeysDown(mapping.keysMapped);
                //keyboard.releaseLastKeys();

                var position = MouseOperations.GetCursorPosition();
                position.X += x;
                position.Y += y;
                MouseOperations.SetCursorPosition(position);


                timerRepeat.Enabled = true;
                return;
            }

            //keyboard.sendKeysDown(mapping.keysMapped);
        }
コード例 #18
0
ファイル: SettingsForm.cs プロジェクト: TinyThor/PS3BluMote
        public SettingsForm()
        {
            for (int i = 0; i < buttonMappings.Length; i++)
            {
                buttonMappings[i] = new ButtonMapping();
            }

            InitializeComponent();

            ListViewItem lvItem;

            foreach (PS3Remote.Button button in Enum.GetValues(typeof(PS3Remote.Button)))
            {
                lvItem = new ListViewItem();
                lvItem.SubItems.Add(button.ToString());
                lvItem.SubItems.Add("");
                lvButtons.Items.Add(lvItem);
            }

            foreach (SendInputAPI.Keyboard.KeyCode key in Enum.GetValues(typeof(SendInputAPI.Keyboard.KeyCode)))
            {
                lvKeys.Items.Add(new ListViewItem(key.ToString()));
            }

            if (!loadSettings())
            {
                saveSettings();
            }
            timerRepeat          = new System.Timers.Timer();
            timerRepeat.Interval = int.Parse(txtRepeatInterval.Text);
            timerRepeat.Elapsed += new System.Timers.ElapsedEventHandler(timerRepeat_Elapsed);



            buttonDump.Visible = DebugLog.isLogging;

            // Finding BT Address of the remote for Hibernation
            if (comboBtAddr.Text.Length != 12 && comboBtAddr.Text.Length != 17)
            {
                UpdateBtAddrList(1000);
            }
            else
            {
                comboBtAddr.Items.Clear();
                comboBtAddr.Items.Add(comboBtAddr.Text);
                comboBtAddr.Items.Add("Search again");
                comboBtAddr.Enabled = true;
            }

            // Saving Device Insertion sounds
            try
            {
                string s;
                bool   save = false;
                s = RegUtils.GetDevConnectedSound();
                if (insertSound.Length == 0 || (insertSound != s && s.Length > 0))
                {
                    insertSound = s;
                    save        = true;
                }
                s = RegUtils.GetDevDisconnectedSound();
                if (removeSound.Length == 0 || (removeSound != s && s.Length > 0))
                {
                    removeSound = s;
                    save        = true;
                }
                if (save)
                {
                    saveSettings();
                }
            }
            catch
            {
                if (DebugLog.isLogging)
                {
                    DebugLog.write("Unexpected error while trying to save Devices insertion/remove sounds.");
                }
            }

            // Restoring Device Insertion sounds in case they have been left blank
            try
            {
                string s;
                s = RegUtils.GetDevConnectedSound();
                if (s.Length == 0 && insertSound.Length > 0)
                {
                    RegUtils.SetDevConnectedSound(insertSound);
                }
                s = RegUtils.GetDevDisconnectedSound();
                if (s.Length == 0 && removeSound.Length > 0)
                {
                    RegUtils.SetDevDisconnectedSound(removeSound);
                }
            }
            catch
            {
                if (DebugLog.isLogging)
                {
                    DebugLog.write("Unexpected error while trying to restore Devices insertion/remove sounds.");
                }
            }

            try
            {
                int hibMs;
                try
                {
                    hibMs = System.Convert.ToInt32(txtMinutes.Text) * 60 * 1000;
                }
                catch
                {
                    if (DebugLog.isLogging)
                    {
                        DebugLog.write("Error while parsing Hibernation Interval, taking Default 3 Minutes");
                    }
                    txtMinutes.Text = "3";
                    hibMs           = 180000;
                }
                remote = new PS3Remote(int.Parse(txtVendorId.Text.Remove(0, 2), System.Globalization.NumberStyles.HexNumber), int.Parse(txtProductId.Text.Remove(0, 2), System.Globalization.NumberStyles.HexNumber));

                remote.BatteryLifeChanged += new EventHandler <EventArgs>(remote_BatteryLifeChanged);
                remote.ButtonDown         += new EventHandler <PS3Remote.ButtonData>(remote_ButtonDown);
                remote.ButtonReleased     += new EventHandler <PS3Remote.ButtonData>(remote_ButtonReleased);

                remote.Connected    += new EventHandler <EventArgs>(remote_Connected);
                remote.Disconnected += new EventHandler <EventArgs>(remote_Disconnected);
                remote.Hibernated   += new EventHandler <EventArgs>(remote_Hibernated);
                remote.Awake        += new EventHandler <EventArgs>(remote_Connected);

                remote.connect();

                remote.btAddress           = comboBtAddr.Text;
                remote.hibernationInterval = hibMs;
                remote.hibernationEnabled  = cbHibernation.Enabled && cbHibernation.Checked;
            }
            catch
            {
                MessageBox.Show("An error occured whilst attempting to load the remote.", "PS3BluMote: Remote error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            keyboard = new SendInputAPI.Keyboard(cbSms.Checked);
        }