示例#1
0
 private static void SetRandomKeyColors(VulcanKeyboard keyboard)
 {
     for (int i = 0; i < 131; i++)
     {
         keyboard.SetKeyColor(i, Color.FromArgb(255 << 24 | r.Next(0, 255 << 16)));
     }
 }
示例#2
0
        static void Main()
        {
            using (VulcanKeyboard keyboard = VulcanKeyboard.Initialize())
            {
                if (keyboard == null)
                {
                    Console.WriteLine("Did not find vulcan!");
                    Console.ReadLine();
                    return;
                }

                Console.WriteLine("Found Vulcan!");
                keyboard.SetColor(Color.Red);
                keyboard.SetKeyColor(Key.W, Color.Blue);
                keyboard.SetKeyColor(Key.A, Color.Blue);
                keyboard.SetKeyColor(Key.S, Color.Blue);
                keyboard.SetKeyColor(Key.D, Color.Blue);

                var watch = new Stopwatch();
                watch.Start();
                bool success = keyboard.Update();
                Console.WriteLine("Set colors: " + success + ", took :" + watch.ElapsedMilliseconds + "ms");
                watch.Stop();
                Console.ReadLine();
                Console.WriteLine("Disconnecting...");
            }
        }
示例#3
0
        private static void SetKeyColorsForAmbilight(VulcanKeyboard keyboard, float[,,] input)
        {
            keyboard.SetKeyColor(Key.W, Color.FromArgb((byte)input[6, 3, 0], (byte)input[6, 3, 1], (byte)input[6, 3, 2]));
            keyboard.SetKeyColor(Key.A, Color.FromArgb((byte)input[3, 4, 0], (byte)input[3, 4, 1], (byte)input[3, 4, 2]));
            keyboard.SetKeyColor(Key.S, Color.FromArgb((byte)input[7, 4, 0], (byte)input[7, 4, 1], (byte)input[7, 4, 2]));
            keyboard.SetKeyColor(Key.D, Color.FromArgb((byte)input[10, 4, 0], (byte)input[10, 4, 1], (byte)input[10, 4, 2]));
            keyboard.SetKeyColor(Key.Z, Color.FromArgb((byte)input[6, 5, 0], (byte)input[6, 5, 1], (byte)input[6, 5, 2]));

            keyboard.SetKeyColor(Key.NUM_ENTER, Color.FromArgb((byte)input[99, 5, 0], (byte)input[99, 5, 1], (byte)input[99, 5, 2]));
        }
示例#4
0
 public bool Initialize()
 {
     if (VulcanKeyboard.Initialize())
     {
         return(true);
     }
     else
     {
         Global.logger.Info("Vulcan device not initialized");
         return(false);
     }
 }
示例#5
0
        public override bool UpdateDevice(Dictionary <DeviceKeys, System.Drawing.Color> keyColors, DoWorkEventArgs e, bool forced = false)
        {
            foreach (var key in keyColors)
            {
                if (KeyMap.TryGetValue(key.Key, out var vulcanKey))
                {
                    VulcanKeyboard.SetKeyColor(vulcanKey, CorrectAlpha(key.Value));
                }
            }

            return(VulcanKeyboard.Update());
        }
示例#6
0
        public bool UpdateDevice(Dictionary <DeviceKeys, Color> keyColors, DoWorkEventArgs e, bool forced = false)
        {
            if (!isInitialized)
            {
                return(false);
            }

            foreach (KeyValuePair <DeviceKeys, Color> key in keyColors)
            {
                Color clr = Color.FromArgb(255, Utils.ColorUtils.MultiplyColorByScalar(key.Value, key.Value.A / 255.0D));
                if (KeyMap.TryGetValue(key.Key, out var vulcanKey))
                {
                    VulcanKeyboard.SetKeyColor(vulcanKey, clr);
                }
            }

            return(VulcanKeyboard.Update());
        }
示例#7
0
 public void Shutdown()
 {
     VulcanKeyboard.Disconnect();
 }
示例#8
0
        public static void Main()
        {
            using VulcanKeyboard keyboard = VulcanKeyboard.Initialize();

            if (keyboard == null)
            {
                Console.WriteLine("Did not find vulcan!");
                Console.ReadLine();
                return;
            }
            var pos = GetKeyPositions();
            //Thread.Sleep(3000);

            //Cursor.Position = new Point(screenLeft, screenTop);
            //Thread.Sleep(200);
            //Cursor.Position = new Point(screenLeft + screenWidth, screenTop);
            //Thread.Sleep(200);
            //Cursor.Position = new Point(screenLeft + screenWidth, screenTop + screenHeight);
            //Thread.Sleep(200);
            //Cursor.Position = new Point(screenLeft, screenTop + screenHeight);
            //Thread.Sleep(200);


            bool initKeyboard = true;
            bool fnPressed    = false;
            bool easyPressed  = false;

            Dictionary <int, byte[]> mapping            = new Dictionary <int, byte[]>();
            Dictionary <int, Color>  alreadyClickedKeys = new Dictionary <int, Color>();

            if (initKeyboard)
            {
                var are  = new AutoResetEvent(false);
                var are2 = new AutoResetEvent(false);
                keyboard.SetColor(Color.Black);
                keyboard.SetKeyColor(0, Color.Green);
                keyboard.Update();

                int i = 0;
                Dictionary <string, byte[]> keys = new Dictionary <string, byte[]>()
                {
                    { "esc", new byte[] { 0x03, 0x00, 0xFB, 0x11 } },
                    { "fn", new byte[] { 0x03, 0x00, 0xFB, 0x77 } },
                    { "easyshift", new byte[] { 0x03, 0x00, 0x0A, 0xFF } },
                    { "oemminus", new byte[] { 0x03, 0x00, 0xFB, 0x5E } },
                };
                ByteEventArgs args = null;

                keyboard.KeyPressedReceived += (object sender, ByteEventArgs even) =>
                {
                    args = even;
                    are2.Set();
                    try
                    {
                        if (args.Bytes.Take(4).SequenceEqual(keys["fn"]))
                        {
                            return;
                        }
                        if (args.Bytes.Take(4).SequenceEqual(keys["easyshift"]))
                        {
                            return;
                        }

                        if (fnPressed && args.Bytes.Take(4).SequenceEqual(keys["oemminus"]) && args.Bytes[4] > 0)
                        {
                            Console.WriteLine("You have made a custom fn hotkey :)");
                        }

                        if (easyPressed && args.Bytes.Take(4).SequenceEqual(keys["oemminus"]) && args.Bytes[4] > 0)
                        {
                            Console.WriteLine("You have made a custom easy hotkey :)");
                        }

                        if (even.Bytes.Take(4).SequenceEqual(keys["esc"]))
                        {
                            i++;
                            keyboard.SetColor(Color.Black);
                            //keyboard.SetKeyColor(i, Color.Green);
                            keyboard.SetKeyColor(i / 2, Color.Green);
                            keyboard.Update();
                            return;
                        }

                        //i++;

                        keyboard.SetColor(Color.Black);
                        //keyboard.SetKeyColor(i, Color.Green);
                        keyboard.SetKeyColor(i / 2, Color.Green);
                        keyboard.Update();

                        //mapping.Add(i, even.Bytes.Take(20).ToArray());

                        //if (i > 300)
                        //    are.Set();
                    }
                    catch (Exception e)
                    {
                    }
                };;
                var task = Task.Run(() =>
                {
                    while (true)
                    {
                        are2.WaitOne();
                        if (args.Bytes.Take(4).SequenceEqual(keys["fn"]))
                        {
                            var block = args.Bytes[4] > 0;
                            if (block)
                            {
                                keyboard.SetColor(Color.Red);
                            }
                            else
                            {
                                keyboard.SetColor(Color.Green);
                            }
                            keyboard.Update();
                            fnPressed = block;
                            try
                            {
                                BlockInput(block);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                                BlockInput(false);
                            }
                        }
                        else if (args.Bytes.Take(4).SequenceEqual(keys["easyshift"]))
                        {
                            var block = args.Bytes[4] < 1;
                            if (block)
                            {
                                keyboard.SetColor(Color.Yellow);
                            }
                            else
                            {
                                keyboard.SetColor(Color.Green);
                            }
                            keyboard.Update();
                            easyPressed = block;
                            try
                            {
                                BlockInput(block);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                                BlockInput(false);
                            }
                        }
                    }
                });
                are.WaitOne();
            }



            CudafyTranslator.GenerateDebug = true;
            CudafyModule km = CudafyTranslator.Cudafy(ePlatform.x64, eArchitecture.OpenCL);//, Version.Parse("9.0"), false, new Type[]{N.GetType()});

            km.GenerateDebug = true;
            GPGPU gpu = CudafyHost.GetDevice(eGPUType.OpenCL, 0);// CudafyModes.Target, CudafyModes.DeviceId);

            //GPGPU gpu = new OpenCLDevice(2);

            gpu.LoadModule(km);
            double frameTime = 1000d / 500d;

            GPUColorBGRA[] colors = new GPUColorBGRA[] {
                //new GPUColorRGB { Red = 0xAD, Green = 0x4A, Blue =0x00},
                //new GPUColorRGB { Red = 0xCE, Green = 0x73, Blue =0x00},
                //new GPUColorRGB { Red = 0x00, Green = 0xAD, Blue =0xF7},
                //new GPUColorRGB { Red = 0xD2, Green = 0xCC, Blue =0x2B},
                //new GPUColorRGB { Red = 0x8C, Green = 0x7A, Blue =0x8B},
                //new GPUColorRGB { Red = 0xEC, Green = 0x00, Blue =0x00},
                //new GPUColorRGB { Red = 0x39, Green = 0x03, Blue =0x03},
                //new GPUColorRGB { Red = 0x4A, Green = 0x4A, Blue = 0x4A },

                ////Minecraft
                new GPUColorBGRA {
                    Red = 43, Green = 113, Blue = 119
                },
                //new GPUColorRGB { Red = 43, Green = 119, Blue = 113 },
                //new GPUColorRGB { Red = 113, Green = 43, Blue = 119 },
                //new GPUColorRGB { Red = 113, Green = 119, Blue = 43 },
                //new GPUColorRGB { Red = 119, Green = 113, Blue = 43 },
                //new GPUColorRGB { Red = 119, Green = 43, Blue = 113 },
            };

            //var ret = gpu.CopyToDevice(colors);

            float[,,] output = new float[keysWidth, keysHeight, 3];
            //float[] debugOutput = new float[screenWidth * screenHeight];
            float[,] outputs = new float[keysWidth, keysHeight];
            //float[] debugOutputs = new float[debugOutput.Length];
            float[,,] devoutput = gpu.Allocate <float>(keysWidth, keysHeight, 3);
            //float[] deboutput = gpu.Allocate<float>(debugOutput.Length);
            //int[] devindices = gpu.Allocate<int>(blockSize.x);
            List <float>  res    = new List <float>();
            HashSet <int> often  = new HashSet <int>();
            HashSet <int> often2 = new HashSet <int>();

            int[]         indices     = new int[blockSize.x];
            byte          clearOftens = 0;
            int           x           = 0;
            int           y           = 0;
            HashSet <int> ys          = new HashSet <int>();
            byte          b           = 0;
            //Thread.Sleep(2000);
            int count = 120;

            var keyColors = new Color[] { Color.Red, Color.Green, Color.Blue };
            var enumVals  = System.Enum.GetValues(typeof(Key)).Cast <int>().ToArray();

            Random r = new Random();

            using (var screenShot = new DirectScreenshot(gpu, screenWidth, screenHeight))
            {
                while (true)
                {
                    //for (int loops = 0; loops < 150; loops++)
                    //{
                    watch.Restart();
                    //(int x, int y) pointerPos = ;
                    screenShot.Capture();

                    //gpu.CopyToDevice(indices, devindices);
                    //gpu.Set(devindices);
                    //gpu.Launch(gridSize, blockSize).ScaleImageKernel(screenShot.rgbValues, ret, devindices, devoutput, deboutput);
                    _ = gpu.Launch(new dim3(keysWidth / 4, keysHeight / 3), new dim3(4, 3)).EnhancedScaleImageKernel(screenShot.rgbValues, screenWidth, screenHeight, devoutput);


                    ////Thread.Sleep(500);
                    gpu.CopyFromDevice(devoutput, output);

                    //var bitmap = new Bitmap(100, 16, PixelFormat.Format24bppRgb);
                    //unsafe
                    //{
                    //    var bmpData = bitmap.LockBits(new Rectangle(new Point(), bitmap.Size), ImageLockMode.WriteOnly, bitmap.PixelFormat);
                    //    var ptr = (byte*)bmpData.Scan0;

                    //    for (int y1 = 0; y1 < 16; y1++)
                    //    {
                    //        for (int x1 = 0; x1 < 100; x1++)
                    //        {

                    //            ptr[(y1 * 100 + x1) * 3 + 0] = (byte)output[x1, y1, 2];
                    //            ptr[(y1 * 100 + x1) * 3 + 1] = (byte)output[x1, y1, 1];
                    //            ptr[(y1 * 100 + x1) * 3 + 2] = (byte)output[x1, y1, 0];
                    //        }
                    //    }
                    //    bitmap.UnlockBits(bmpData);
                    //}
                    //bitmap.Save("TestImage.bmp");
                    ;
                    //gpu.CopyFromDevice(deboutput, debugOutput);
                    //gpu.CopyFromDevice(devindices, indices);
                    //var asdq = indices.Select((x, i) => x==0 ? -1 : (i * gridSize.x)).Where(x=>x!=-1).ToList();
                    //Console.Error.WriteLine("Milliseconds Array Sort begin: " + watch.Elapsed.TotalMilliseconds);

                    //for (int i = 0; i < output.Length; i+=gridSize.x)
                    //{
                    //    for (int oz = i; oz < gridSize.x + i; oz++)
                    //    {
                    //        var item = (int)output[oz];
                    //        if (item <= 0)
                    //            break;
                    //        count++;
                    //        //Console.WriteLine(/* LeftClick*/(item % screenWidth, item / screenWidth));
                    //        LeftClick(item % screenWidth, item / screenWidth);
                    //        //Thread.Sleep(333);
                    //    }
                    //}
                    //var zerosCount = debugOutput.Count(z => z != 0);
                    //watch.Restart();
                    //var onesAndOnlys = output.Count(z => z == 0);
                    //outputs = output.Where(f => f != 0).ToArray();
                    //Console.WriteLine(watch.Elapsed + " took where");
                    //watch.Restart();

                    //Array.Sort(output);
                    //output = output.Reverse().ToArray();
                    //Console.WriteLine(watch.Elapsed + " took sort");
                    //watch.Stop();
                    //for (int i = 0; i < outputs.Length/*&& count < 200*/; i++)
                    //{
                    //    var item = (int)outputs[i];
                    //    if (item != 0)
                    //        count++;
                    //    if (Control.IsKeyLocked(Keys.CapsLock))
                    //        break;
                    //    if (item == 0)
                    //        break;
                    //    x = item % screenWidth;
                    //    y = item / screenWidth;
                    //    //if (x == pointerPos.x && y == pointerPos.y)
                    //    //    Console.WriteLine("Pointer in Array");
                    //    //if (often2.Contains(item))
                    //    //    continue;
                    //    //if (often.Contains(item))
                    //    //{
                    //    //    if (!often2.Contains(item))
                    //    //    {
                    //    if (x > ourscreenLeft && x < ourscreenWidth + ourscreenLeft
                    //        && y > ourscreenTop && y < ourscreenTop + ourscreenHeight
                    //        && x == 666
                    //        && false)
                    //    {
                    //        //ys.Add(y);
                    //        //count++;
                    //        //Console.WriteLine($"{x}:{y}");
                    //        LeftClick(item % screenWidth + 243, item / screenWidth + 20); //Insaniquarium
                    //    }
                    //    //else
                    //    {
                    //        ;
                    //    }
                    //    //if ((item % screenWidth) == 26)
                    //    //LeftClick((item % screenWidth) + screenLeft + 243, (item / screenWidth) + 20);
                    //    //often2.Add(item);
                    //    //    }
                    //    //}
                    //    //else
                    //    //{
                    //    //    b++;

                    //    //    LeftClick(item % screenWidth, item / screenWidth);
                    //    //    often.Add(item);
                    //    //}

                    //    count++;
                    //    //LeftClick(item % screenWidth, item / screenWidth);
                    //    //Thread.Sleep(1);


                    //    //break;
                    //    //count++;
                    //    //Console.WriteLine(/* LeftClick*/(item % screenWidth, item / screenWidth));
                    //}
                    //b++;
                    //if (!Control.IsKeyLocked(Keys.CapsLock))
                    //{
                    //    //mouse_event((int)MouseEventFlags.MOUSEEVENTF_WHEEL, 0, 0, -120, 0);
                    //    //Thread.Sleep(50);
                    //}

                    watch.Stop();
                    //Console.WriteLine("Found: " + count);
                    //count = 0;
                    //var l = output.Select((x,i) => (x,i)).Where(x => x.x > 0).Select(x=>((float)x.i) / 2025).ToList();
                    //Console.WriteLine(count + " | " + l.Count);
                    //Console.Write("Found: " +  + " | ");
                    double elapsed = watch.Elapsed.TotalMilliseconds;
                    //Console.Error.WriteLine("Milliseconds: " + watch.Elapsed.TotalMilliseconds);


                    var color = keyColors[count % 3];
                    keyboard.SetColor(Color.Orange);
                    //keyboard.SetKeyColor((Key)enumVals[(count / 3)], color);
                    //keyboard.SetKeyColor((Key)enumVals[(((count / 3)+ enumVals.Length-1) % enumVals.Length)], Color.Black);
                    //count = (count + 1)%(enumVals.Length* 3);
                    //keyboard.SetColor(Color.FromArgb((count >> 16) & 0xff, (count >> 8) & 0xff, count & 0xff));
                    //count += r.Next(0, 255);
                    //keyboard.SetColor(Color.Green);
                    //for (int i = 0; i < 131; i++)
                    //{
                    //    keyboard.SetKeyColor((Key)i, Color.FromArgb(255 << 24 | r.Next(0, 255 << 16)));
                    //}

                    SetKeyColorsForAmbilight(keyboard, output);


                    //watch.Restart();
                    keyboard.Update();
                    //watch.Stop();
                    //Console.WriteLine("Set colors took:" + watch.ElapsedMilliseconds + "ms");
                    elapsed += watch.Elapsed.TotalMilliseconds;


                    //Thread.Sleep((int)Math.Max((frameTime - watch.Elapsed.TotalMilliseconds), 0));
                    Thread.Sleep(1);
                    //Thread.Sleep(Math.Min(33, Math.Max(0, 33 - (int)elapsed)));
                    //clearOftens++;
                    //if (clearOftens % 20 == 0)
                    //    often.Clear();
                    //else if (clearOftens == 101)
                    //{
                    //    often.Clear();
                    //    often2.Clear();
                    //    clearOftens = 0;
                    //}
                    //mouse_event((int)MouseEventFlags.MOUSEEVENTF_WHEEL, 0, 0, -120, 0);
                    //}
                    //Console.ReadKey();
                }
            }
            gpu.FreeAll();
            Console.Read();
        }
示例#9
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();
            }
        }
示例#10
0
 public override void Shutdown() => VulcanKeyboard.Disconnect();
示例#11
0
 public override bool Initialize() => VulcanKeyboard.Initialize();