Beispiel #1
0
 private static KeyNode AddOrGetNode(KeyNode parent, LedKey key)
 {
     if (parent.Children.TryGetValue(key, out var node))
     {
         return(node);
     }
     node = new KeyNode()
     {
         Key = key
     };
     parent.Children.Add(key, node);
     return(node);
 }
Beispiel #2
0
        public void CreateNode(List <LedKey> hotkey, Action <VulcanKeyboard> action)
        {
            KeyNode curNode = this;

            for (int i = 0; i < hotkey.Count; i++)
            {
                var key    = hotkey[i];
                var tmpKey = AddOrGetNode(curNode, key);
                //if (tmpKey.KeineAhnungAction != null)
                //{
                //    throw new Exception("node already has an action");
                //}
                curNode = tmpKey;
                if (i == hotkey.Count - 1)
                {
                    tmpKey.KeineAhnungAction = action;
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //var scanner = new DeviceScanner(0x1E7D, 0x3098);
            //scanner.StartAsyncScan();

            //var dev = new USBDevice(0x1E7D, 0x3098, null);
            ////scanner.DeviceArrived += (o, s) => {; };
            ////scanner.DeviceRemoved += (o, s) => {; };
            //dev.InputReportArrivedEvent += Dev_InputReportArrivedEvent;
            //dev.StartAsyncRead();
            //Console.ReadLine();
            //scanner.StopAsyncScan();
            AutoResetEvent are = new AutoResetEvent(true);


            //tree.CreateNode(new List<LedKey> { LedKey.FN_Key, LedKey.M, LedKey.O, LedKey.OEMPERIOD }, (vk) => { Console.WriteLine("Jay"); });
            //tree.CreateNode(new List<LedKey> { LedKey.FN_Key, LedKey.M, LedKey.P, LedKey.OEMPERIOD }, (vk) => { Console.WriteLine("Jay2"); });
            //tree.CreateNode(new List<LedKey> { LedKey.FN_Key, LedKey.A, LedKey.P, LedKey.OEMPERIOD }, (vk) => { Console.WriteLine("Jay123"); });

            //tree.CreateNode(new List<LedKey> { LedKey.LEFT_CONTROL, LedKey.C }, (vk) => { Console.WriteLine("Copy"); });
            //tree.CreateNode(new List<LedKey> { LedKey.LEFT_CONTROL, LedKey.K }, (vk) => { Console.WriteLine("KD"); });

            //tree.CreateNode(new List<LedKey> { LedKey.RIGHT_CONTROL, LedKey.M, LedKey.O, LedKey.OEMPERIOD }, (vk) => { Console.WriteLine("JayCtrl"); });
            //tree.CreateNode(new List<LedKey> { LedKey.RIGHT_CONTROL, LedKey.M, LedKey.P, LedKey.OEMPERIOD }, (vk) => { Console.WriteLine("JayCtrl2"); });
            //tree.CreateNode(new List<LedKey> { LedKey.RIGHT_CONTROL, LedKey.A, LedKey.P, LedKey.OEMPERIOD }, (vk) => { Console.WriteLine("JayCtrl123"); });

            //tree.CreateNode(new List<LedKey> { LedKey.RIGHT_CONTROL, LedKey.FN_Key, LedKey.RIGHT_CONTROL, LedKey.FN_Key }, (vk) => { Console.WriteLine("What?"); });
            //tree.CreateNode(new List<LedKey> { LedKey.RIGHT_CONTROL, LedKey.FN_Key }, (vk) => { Console.WriteLine("What? Early exit"); });
            //tree.CreateNode(new List<LedKey> { LedKey.RIGHT_CONTROL, LedKey.FN_Key, LedKey.R }, (vk) => { Console.WriteLine("Later Early Exit"); });

            //tree.CreateNode(new List<LedKey> { LedKey.RIGHT_CONTROL, LedKey.FN_Key, LedKey.RIGHT_CONTROL, LedKey.LEFT_ALT }, (vk) => { Console.WriteLine("What??"); });
            //tree.CreateNode(new List<LedKey> { LedKey.RIGHT_CONTROL, LedKey.RIGHT_CONTROL }, (vk) => { Console.WriteLine("Exit Virtual Box Capture"); });

            //tree.CreateNode(new List<LedKey> { LedKey.FN_Key, LedKey.B, LedKey.A, LedKey.N, LedKey.A, LedKey.N, LedKey.A, LedKey.S }, (vk) => { Console.WriteLine("Bananas"); });

            //tree.CreateNode(new List<LedKey> { LedKey.FN_Key, LedKey.B, LedKey.A, LedKey.N, LedKey.A, LedKey.N, LedKey.E, LedKey.N, LedKey.B, LedKey.R, LedKey.O, LedKey.T }, (vk) => { Console.WriteLine("Backt eh niemand"); });

            tree.CreateNode(new List <LedKey> {
                LedKey.Q, LedKey.Q
            }, (vk) =>
            {
                Console.WriteLine("New Random Colors");
                SetRandomKeyColors(vk);
                are.Set();
            });
            //tree.CreateNode(new List<LedKey> { LedKey.Q, LedKey.W }, (vk) => { Console.WriteLine("Throw Granade"); });
            //tree.CreateNode(new List<LedKey> { LedKey.Q, LedKey.E }, (vk) => { Console.WriteLine("Dont even know"); });


            foreach (var color in typeof(Color).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static).Where(x => x.PropertyType == typeof(Color)))
            {
                var hotkey = new List <LedKey> {
                    LedKey.FN_Key
                };

                foreach (var key in color.Name.ToUpper())
                {
                    hotkey.Add(Enum.Parse <LedKey>(key.ToString()));
                }

                tree.CreateNode(hotkey, (vk) =>
                {
                    Console.WriteLine("Set Color to: " + color.Name);
                    vk.SetColor((Color)color.GetValue(null));
                    are.Set();
                });
            }


            VulcanKeyboard keyboard = VulcanKeyboard.Initialize();

            SetRandomKeyColors(keyboard);

            keyboard.VolumeKnobTurnedReceived += (s, e) =>
            {
                //Console.WriteLine("Knob reached limit; Turned to direction " + (e.TurnedRight ? "Right" : "Left"));
            };
            keyboard.VolumeKnobFxPressedReceived += (s, e) =>
            {
                //Console.WriteLine("FX Knob change value to " + (e.Data));
                if (s is VulcanKeyboard vk)
                {
                    vk.Brightness = e.Data;
                    are.Set();
                }
            };
            keyboard.VolumeKnobPressedReceived += (s, e) =>
            {
                //Console.WriteLine("Volume knob \"clicked\" " + e.IsPressed);
            };
            keyboard.KeyPressedReceived += (s, e) =>
            {
                if (!(s is VulcanKeyboard vk))
                {
                    return;
                }

                currentNode ??= tree;
                if (!e.IsPressed)
                {
                    if (e.Key == LedKey.ESC && currentNode != tree)
                    {
                        currentNode = tree;
                        vk.SetColors(lastColorCopy);
                        are.Set();
                    }
                }

                if (e.IsPressed)
                {
                    if (e.Key == LedKey.ENTER && currentNode.KeineAhnungAction != null)
                    {
                        vk.SetColors(lastColorCopy);
                        currentNode.KeineAhnungAction(vk);
                        currentNode = tree;
                    }
                    else if (!currentNode.Children.TryGetValue(e.Key, out var node) && currentNode != tree)
                    {
                        vk.SetKeyColor(e.Key, Color.Red);
                        are.Set();
                        return;
                    }

                    else if (node is not null)
                    {
                        if (currentNode == tree)
                        {
                            lastColorCopy = vk.GetLastSendColorsCopy();
                        }

                        if (node.KeineAhnungAction == null && !node.HasSinglePath)
                        {
                            currentNode = node;
                            vk.SetColor(Color.Black);
                            foreach (var item in currentNode.Children)
                            {
                                vk.SetKeyColor(item.Key, Color.Green);
                            }

                            are.Set();
                            return;
                        }
                        else if (node.KeineAhnungAction != null && node.Children.Count > 0)
                        {
                            currentNode = node;
                            vk.SetColor(Color.Black);
                            foreach (var item in currentNode.Children)
                            {
                                vk.SetKeyColor(item.Key, Color.Green);
                            }

                            vk.SetKeyColor(LedKey.ENTER, Color.BlueViolet);
                            are.Set();

                            return;
                        }
                        currentNode = tree;
                        vk.SetColors(lastColorCopy);
                        node.SinglePathChild.KeineAhnungAction(vk);
                    }
                }

                //Console.WriteLine($"Key Pressed {e.Key} {e.IsPressed}"  );

                //if (e.IsPressed)
                //    vk.SetKeyColor(e.Key, Color.Blue);
                //else
                //    vk.SetKeyColor(e.Key, Color.Black);
                //are.Set();
            };

            var t = Task.Run(async() =>
            {
                while (true)
                {
                    await keyboard.Update();
                    are.WaitOne();

                    Thread.Sleep(16);
                }
            });

            while (true)
            {
                Console.ReadLine();
            }
        }