public void RefreshStreamDeckPage()
        {
            if (ButtonMatrixPanel == null || MainWindowPanel == null)
            {
                return;
            }

            for (int i = 0; i < 15; i++)
            {
                Bitmap bmp_up            = ButtonMatrixPanel.btnList[i].GetRenderBitmap();
                Bitmap bmp_down          = ButtonMatrixPanel.btnList[i].GetRenderBitmap(true);
                StreamDeckKeyBitmap sdkb = StreamDeckKeyBitmap.FromDrawingBitmap(bmp_up);
                if (Deck != null)
                {
                    Deck.SetKeyBitmap(i, sdkb);
                }

                // Save bitmap to ButtonData
                if (ButtonMatrixPanel.btnList[i].DataContext != null)
                {
                    (ButtonMatrixPanel.btnList[i].DataContext as ButtonData).ButtonBitmapBuf_UP   = bmp_up;
                    (ButtonMatrixPanel.btnList[i].DataContext as ButtonData).ButtonBitmapBuf_DOWN = bmp_down;
                }
            }
        }
Exemple #2
0
        private static void Deck_KeyPressed(object sender, StreamDeckKeyEventArgs e)
        {
            var d = sender as IStreamDeck;

            if (d == null)
            {
                return;
            }

            if (e.IsDown)
            {
                rnd.NextBytes(rgbBuffer);
                var randomColor = StreamDeckKeyBitmap.FromRGBColor(rgbBuffer[0], rgbBuffer[1], rgbBuffer[2]);
                d.SetKeyBitmap(e.Key, randomColor);
            }
        }
        private void Deck_KeyPressed(object sender, StreamDeckKeyEventArgs e)
        {
            var d = sender as IStreamDeck;

            if (d == null)
            {
                return;
            }

            if (Deck == null)
            {
                return;
            }

            if (e.IsDown)
            {
                if (DateTime.Now - lastKeyPress < TimeSpan.FromMilliseconds(250))
                {
                    return;
                }

                lastKeyPress = DateTime.Now;
                // Key Down
                MainWindowPanel.Dispatcher.Invoke(() =>
                {
                    Bitmap bmp = (ButtonMatrixPanel.btnList[e.Key].DataContext as ButtonData).ButtonBitmapBuf_DOWN;
                    StreamDeckKeyBitmap sdkb = StreamDeckKeyBitmap.FromDrawingBitmap(bmp);
                    Deck.SetKeyBitmap(e.Key, sdkb);
                    ButtonData bd = ButtonMatrixPanel.btnList[e.Key].DataContext as ButtonData;
                    ButtonFuncProcess(bd);
                });
            }
            else
            {
                // Key up
                MainWindowPanel.Dispatcher.Invoke(() =>
                {
                    Bitmap bmp = (ButtonMatrixPanel.btnList[e.Key].DataContext as ButtonData).ButtonBitmapBuf_UP;
                    StreamDeckKeyBitmap sdkb = StreamDeckKeyBitmap.FromDrawingBitmap(bmp);
                    Deck.SetKeyBitmap(e.Key, sdkb);
                });
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            //Create some color we use later to draw the flag of austria
            var red       = StreamDeckKeyBitmap.FromRGBColor(237, 41, 57);
            var white     = StreamDeckKeyBitmap.FromRGBColor(255, 255, 255);
            var rowColors = new StreamDeckKeyBitmap[] { red, white, red };

            //Open the Stream Deck device
            using (var deck = StreamDeck.FromHID())
            {
                deck.SetBrightness(100);

                //Send the bitmap informaton to the device
                for (int i = 0; i < deck.NumberOfKeys; i++)
                {
                    deck.SetKeyBitmap(i, rowColors[i / 5]);
                }
            }
        }
Exemple #5
0
 public StreamDeckKeyBitmap getImage()
 {
     if (ImageType == ImageSaveType.Image_File)
     {
         if (File.Exists(ImageLocation))
         {
             return(StreamDeckKeyBitmap.FromFile(ImageLocation));
         }
         else
         {
             return(StreamDeckKeyBitmap.FromFile("Resources\\default.png"));
         }
     }
     else if (ImageType == ImageSaveType.Image_Color)
     {
         return(StreamDeckKeyBitmap.FromRGBColor(ImageColor.R, ImageColor.G, ImageColor.B));
     }
     else
     {
         return(StreamDeckKeyBitmap.FromRawBitmap(ImageToByte(OpenStreamDeck.Properties.Resources._default)));
     }
 }
Exemple #6
0
        static void Run()
        {
            using (var deck = StreamDeck.FromHID())
            {
                deck.SetBrightness(100);

                /////////////////////////
                //   -key locations-   //
                //    4  3  2  1  0    //
                //    9  8  7  6  5    //
                //   14 13 12 11 10    //
                /////////////////////////

                Console.WriteLine("Loading Keys...");

                Keys.Add(new KeyList {
                    KeyName = "Preview 1", KeyType = KEY_PREVIEW, Loc = 14, IconDisabled = "icons\\1_grey.png", IconEnabled = "icons\\1_green.png", Input = 1
                });
                Keys.Add(new KeyList {
                    KeyName = "Preview 2", KeyType = KEY_PREVIEW, Loc = 13, IconDisabled = "icons\\2_grey.png", IconEnabled = "icons\\2_green.png", Input = 2
                });
                Keys.Add(new KeyList {
                    KeyName = "Preview 3", KeyType = KEY_PREVIEW, Loc = 12, IconDisabled = "icons\\3_grey.png", IconEnabled = "icons\\3_green.png", Input = 3
                });
                Keys.Add(new KeyList {
                    KeyName = "Preview 4", KeyType = KEY_PREVIEW, Loc = 11, IconDisabled = "icons\\4_grey.png", IconEnabled = "icons\\4_green.png", Input = 4
                });

                Keys.Add(new KeyList {
                    KeyName = "Output 1", KeyType = KEY_OUTPUT, Loc = 9, IconDisabled = "icons\\1_grey.png", IconEnabled = "icons\\1_red.png", Input = 1
                });
                Keys.Add(new KeyList {
                    KeyName = "Output 2", KeyType = KEY_OUTPUT, Loc = 8, IconDisabled = "icons\\2_grey.png", IconEnabled = "icons\\2_red.png", Input = 2
                });
                Keys.Add(new KeyList {
                    KeyName = "Output 3", KeyType = KEY_OUTPUT, Loc = 7, IconDisabled = "icons\\3_grey.png", IconEnabled = "icons\\3_red.png", Input = 3
                });
                Keys.Add(new KeyList {
                    KeyName = "Output 4", KeyType = KEY_OUTPUT, Loc = 6, IconDisabled = "icons\\4_grey.png", IconEnabled = "icons\\4_red.png", Input = 4
                });

                Keys.Add(new KeyList {
                    KeyName = "Overlay 1", KeyType = KEY_OVERLAY, Loc = 4, IconDisabled = "icons\\1_grey.png", IconEnabled = "icons\\1_yel.png", Input = 1, Active = false
                });
                Keys.Add(new KeyList {
                    KeyName = "Overlay 2", KeyType = KEY_OVERLAY, Loc = 3, IconDisabled = "icons\\2_grey.png", IconEnabled = "icons\\2_yel.png", Input = 2, Active = false
                });
                Keys.Add(new KeyList {
                    KeyName = "Overlay 3", KeyType = KEY_OVERLAY, Loc = 2, IconDisabled = "icons\\3_grey.png", IconEnabled = "icons\\3_yel.png", Input = 3, Active = false
                });

                Keys.Add(new KeyList {
                    KeyName = "Stream", KeyType = KEY_STREAM, Loc = 1, IconDisabled = "icons\\stream_off.png", IconEnabled = "icons\\stream_on.png"
                });
                Keys.Add(new KeyList {
                    KeyName = "Record", KeyType = KEY_RECORD, Loc = 0, IconDisabled = "icons\\record_off.png", IconEnabled = "icons\\record_on.png"
                });
                Keys.Add(new KeyList {
                    KeyName = "Quick Play", KeyType = KEY_QUICKPLAY, Loc = 5, IconDisabled = "icons\\quickplay.png", IconEnabled = "icons\\quickplay.png"
                });
                Keys.Add(new KeyList {
                    KeyName = "Cut", KeyType = KEY_CUT, Loc = 10, IconDisabled = "icons\\cut.png", IconEnabled = "icons\\cut.png"
                });

                deck.ClearKeys();

                //Load keys
                foreach (KeyList KeyInit in Keys)
                {
                    //combined += thing.Name;
                    deck.SetKeyBitmap(KeyInit.Loc, StreamDeckKeyBitmap.FromFile(KeyInit.IconDisabled));
                }

                Console.WriteLine("Keys loaded, doing update...");

                Boolean status = UpdateKeyStatus(deck, true);  //first update
                if (status)
                {
                    Console.WriteLine("Connected.  Performing initial key status update.");
                    Console.WriteLine("Waiting for input.");
                }
                else
                {
                    Console.WriteLine("vMix Connection Error, retrying....");
                    while (status == false)
                    {
                        status = UpdateKeyStatus(deck, true);
                    }
                    Console.WriteLine("Connected to vMix.  Waiting for key input.");
                }

                //Console.WriteLine("keypress listen start");
                deck.KeyPressed += Deck_KeyPressed; //listen for keypresses

                while (true)
                {
                    Thread.Sleep(2000);  //two second update to check for changes not triggered by a keypress
                    UpdateKeyStatus(deck);
                    //Console.WriteLine("Update keys LOOP.");
                }
            }
        }
Exemple #7
0
        private static Boolean UpdateKeyStatus(object sender, Boolean init = false)
        {
            var d = sender as IStreamDeck;

            if (d == null)
            {
                return(false);
            }
            if (WebClient.GetStatus() == false)
            {
                Console.WriteLine("vMix Connection Failed.");
                return(false);
            }
            //Console.WriteLine("UKS-1, Before Init");
            //first time, update key status
            if (init == true)
            {
                if ((WebClient.ActiveInput > 4))
                {
                    Console.WriteLine("Current Active Input > 4");
                    var PK_Index = Keys.FindIndex(Keys => (Keys.Input == WebClient.PreviewInput) && (Keys.KeyType == KEY_PREVIEW));
                    d.SetKeyBitmap(Keys[PK_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[PK_Index].IconEnabled));
                }
                else if (WebClient.PreviewInput > 4)
                {
                    Console.WriteLine("Current Preview Input > 4");
                    var AK_Index = Keys.FindIndex(Keys => (Keys.Input == WebClient.ActiveInput) && (Keys.KeyType == KEY_OUTPUT));
                    d.SetKeyBitmap(Keys[AK_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[AK_Index].IconEnabled));
                }
                else
                {
                    try
                    {
                        var AK_Index = Keys.FindIndex(Keys => (Keys.Input == WebClient.ActiveInput) && (Keys.KeyType == KEY_OUTPUT));
                        var PK_Index = Keys.FindIndex(Keys => (Keys.Input == WebClient.PreviewInput) && (Keys.KeyType == KEY_PREVIEW));
                        d.SetKeyBitmap(Keys[AK_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[AK_Index].IconEnabled));
                        d.SetKeyBitmap(Keys[PK_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[PK_Index].IconEnabled));
                    }
                    catch (Exception ex) { Console.WriteLine(ex); return(false); }
                }
            }
            //Console.WriteLine("UKS-2, after INIT");
            //check overlay status
            foreach (OverlayStatus overlay in WebClient.OverlayStatus)
            {
                try
                {
                    var OverlayKey_Index = Keys.FindIndex(Keys => (Keys.Input == overlay.number) && (Keys.KeyType == KEY_OVERLAY));
                    //Console.Write(overlay.number + ": " + overlay.Enabled + ", ");
                    if (overlay.Enabled)
                    {
                        d.SetKeyBitmap(Keys[OverlayKey_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[OverlayKey_Index].IconEnabled));
                        Keys[OverlayKey_Index].Active = true;
                    }
                    else
                    {
                        d.SetKeyBitmap(Keys[OverlayKey_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[OverlayKey_Index].IconDisabled));
                        Keys[OverlayKey_Index].Active = false;
                    }
                }
                catch { }
            }
            //Console.WriteLine("UKS-3, after Overlay");
            //update active
            if (WebClient.ActiveChanged)
            {
                if ((WebClient.ActiveInput > 4))
                {
                    Console.WriteLine("Current Active Input > 4");
                    if (WebClient.OldActive <= 4)
                    {
                        var oAK_Index = Keys.FindIndex(Keys => (Keys.Input == WebClient.OldActive) && (Keys.KeyType == KEY_OUTPUT));
                        d.SetKeyBitmap(Keys[oAK_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[oAK_Index].IconDisabled));
                    }
                }
                else
                {
                    if (WebClient.OldActive <= 4)
                    {
                        var oAK_Index = Keys.FindIndex(Keys => (Keys.Input == WebClient.OldActive) && (Keys.KeyType == KEY_OUTPUT));
                        d.SetKeyBitmap(Keys[oAK_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[oAK_Index].IconDisabled));
                    }
                    var AK_Index = Keys.FindIndex(Keys => (Keys.Input == WebClient.ActiveInput) && (Keys.KeyType == KEY_OUTPUT));
                    d.SetKeyBitmap(Keys[AK_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[AK_Index].IconEnabled));
                }
                WebClient.ActiveChanged = false;
            }
            //Console.WriteLine("UKS-4, After Active");
            //update preview
            if (WebClient.PreviewChanged)
            {
                if ((WebClient.PreviewInput > 4))
                {
                    Console.WriteLine("Current Preview Input > 4");
                    if (WebClient.OldPreview <= 4)
                    {
                        var oPK_Index = Keys.FindIndex(Keys => (Keys.Input == WebClient.OldPreview) && (Keys.KeyType == KEY_PREVIEW));
                        d.SetKeyBitmap(Keys[oPK_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[oPK_Index].IconDisabled));
                    }
                }
                else
                {
                    if (WebClient.OldPreview <= 4)
                    {
                        var oPK_Index = Keys.FindIndex(Keys => (Keys.Input == WebClient.OldPreview) && (Keys.KeyType == KEY_PREVIEW));
                        d.SetKeyBitmap(Keys[oPK_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[oPK_Index].IconDisabled));
                    }
                    var PK_Index = Keys.FindIndex(Keys => (Keys.Input == WebClient.PreviewInput) && (Keys.KeyType == KEY_PREVIEW));
                    d.SetKeyBitmap(Keys[PK_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[PK_Index].IconEnabled));
                }
                WebClient.PreviewChanged = false;
            }
            //Console.WriteLine("UKS-5, After Preview");
            //update recording status
            var RecordKey_Index = Keys.FindIndex(Keys => Keys.KeyType == KEY_RECORD);

            if (WebClient.Recording)
            {
                d.SetKeyBitmap(Keys[RecordKey_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[RecordKey_Index].IconEnabled));
            }
            else
            {
                d.SetKeyBitmap(Keys[RecordKey_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[RecordKey_Index].IconDisabled));
            }
            //Console.WriteLine("UKS-6, After Recording Status");
            //update streaming status
            var StreamKey_Index = Keys.FindIndex(Keys => Keys.KeyType == KEY_STREAM);

            if (WebClient.Streaming)
            {
                d.SetKeyBitmap(Keys[StreamKey_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[StreamKey_Index].IconEnabled));
            }
            else
            {
                d.SetKeyBitmap(Keys[StreamKey_Index].Loc, StreamDeckKeyBitmap.FromFile(Keys[StreamKey_Index].IconDisabled));
            }
            //Console.WriteLine("UKS-6, After Streaming Status - DONE");
            return(true);
        }
Exemple #8
0
        static void Main(string[] args)
        {
            /////////////////////////
            //   -key locations-   //
            //    4  3  2  1  0    //
            //    9  8  7  6  5    //
            //   14 13 12 11 10    //
            /////////////////////////

            //Set key locations
            var key_location_hours   = 8;
            var key_location_minutes = 7;
            var key_location_ampm    = 6;

            //Attempt to initially give the buttom time to change the image before starting the loop to avoid display lag
            System.Threading.Thread.Sleep(500);

            //Open the Stream Deck device
            using (var deck = StreamDeck.FromHID())
            {
                //Set loop
                while (true)
                {
                    //Get the current time (hours, minutes and am/pm)
                    string time_output_hours   = DateTime.Now.ToString("hh");
                    string time_output_minutes = DateTime.Now.ToString("mm");
                    string time_output_ampm    = DateTime.Now.ToString("tt");

                    //Check if hours string is not empty
                    if (!string.IsNullOrEmpty(time_output_hours))
                    {
                        //check if hours start with "0"
                        if (time_output_hours.StartsWith("0"))
                        {
                            //remove starting "0" from string
                            time_output_hours = time_output_hours.Remove(0, 1);
                        }
                        //send results to Set_Time to deal with
                        Set_Time(time_output_hours, key_location_hours);
                    }

                    //Check if minutes string is not empty
                    if (!string.IsNullOrEmpty(time_output_minutes))
                    {
                        //send results to Set_Time to deal with
                        Set_Time(time_output_minutes, key_location_minutes);
                    }

                    //Check if am/pm string is not empty
                    if (!string.IsNullOrEmpty(time_output_ampm))
                    {
                        //send results to Set_Time to deal with
                        Set_Time(time_output_ampm, key_location_ampm);
                    }

                    //Wait 1 second before restarting loop
                    System.Threading.Thread.Sleep(1000);

                    //Check for key presses, if pressed send exit command
                    deck.KeyPressed += Deck_KeyPressed;
                }

                void Set_Time(string time_result, int key_location)
                {
                    //Set corresponding icons to the time of day
                    string time_result_icon = time_result + ".png";
                    var    clock_bitmap     = StreamDeckKeyBitmap.FromFile("clock_icons\\" + time_result_icon);

                    deck.SetKeyBitmap(key_location, clock_bitmap);
                }

                void Deck_KeyPressed(object sender, StreamDeckKeyEventArgs e)
                {
                    //Kill console App
                    Environment.Exit(0);
                }
            }
        }