static void Main(string[] args) { using (var deck = StreamDeck.OpenDevice()) { deck.ClearKeys(); var map = new Map(); var player = new Player(); var screenManager = new ScreenManager(deck); var titleScreen = new TitleScreen(screenManager); var powerScreen = new PowersScreen(screenManager, player); var mapScreen = new MapScreen(screenManager, map, player); titleScreen.NextScreen = powerScreen; powerScreen.NextScreen = mapScreen; titleScreen.Activate(); while (true) { Task.Delay(1000).GetAwaiter().GetResult(); } } }
private async void frmMain_Load(object sender, EventArgs e) { // setup notification sounds this._notificationPlayer = new WMPLib.WindowsMediaPlayer(); this._notificationPlayer.URL = @"Assets\Sounds\notification.mp3"; this._notificationPlayer.controls.stop(); // load up the buttons this._streamDeckButtons = Settings.LoadButtons(); // initialize the stream deck _streamDeck = new StreamDeck(this._streamDeckButtons); // create the notification object this._notification = new Notifications(); // check to see if we have permission to access the notifications if (!(await this._notification.RequestAccess())) { throw new Exception("Unable to get notification access from user"); } // setup the timer this._notificationCheckTimer = new Timer(); this._notificationCheckTimer.Interval = (int)TimeSpan.FromSeconds(Constants.CHECK_TIME_IN_SECONDS).TotalMilliseconds; this._notificationCheckTimer.Tick += new EventHandler(CheckNotification); this._notificationCheckTimer.Start(); // timer will execute every minute, so let's check notifications right on start up this.CheckNotification(null, null); }
private void InitJoystick() { lock (lockObj) { // Verify the vJoy driver is enabled. if (!VirtualJoystick.vJoyEnabled()) { throw new VJoyNotEnabledException("vJoy is not enabled! Please install and enable vJoy!"); } // Get the state of the requested device. VjdStat Status = VirtualJoystick.GetVJDStatus(JoystickID); switch (Status) { case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_BUSY: case VjdStat.VJD_STAT_MISS: default: throw new VJoyAccessException("Cannot access vJoy! Code: " + Status.ToString()); } ; // Acquire the target joystick. if (!VirtualJoystick.AcquireVJD(JoystickID)) { throw new VJoyAcquisitionException("Could not acquire vJoy with ID: " + JoystickID.ToString()); } // Open the Stream Deck device. try { Deck = StreamDeck.OpenDevice(); } catch (Exception ex) { //Catch the internal StreamDeck error and handle it our way. Deck = null; #if DEBUG Console.WriteLine(ex.ToString()); #endif } if (Deck == null || !Deck.IsConnected) { throw new StreamDeckAccessException("Stream Deck could not be opened!"); } // Set the brightness of the keys. Deck.SetBrightness(100); // Register the key pressed event handler. Deck.KeyStateChanged += StreamDeckKeyPressed; } ReloadButtonImages(); }
static void Main(string[] args) { using (var deck = StreamDeck.OpenDevice()) { PlayVideoAForgeFFMPEG(deck, @"C:\testvideo.mp4"); } }
private void frmMain_FormClosing(object sender, FormClosingEventArgs e) { // run cleanup this._notificationCheckTimer.Start(); this._notificationCheckTimer = null; this._streamDeck.Dispose(); this._streamDeck = null; }
private void Current_Exit(object sender, ExitEventArgs e) { var deck = StreamDeck.OpenDevice(); deck.SetBrightness(50); deck.ShowLogo(); _notifyIcon?.Icon?.Dispose(); _notifyIcon?.Dispose(); }
static void Main(string[] args) { using (var deck = StreamDeck.OpenDevice()) using (var bmp = (Bitmap)Image.FromFile(@"C:\testimage.png")) { deck.DrawFullScreenBitmap(bmp); Console.ReadKey(); } }
private static void CleanExit(object sender, EventArgs e) { using (var deck = StreamDeck.FromHID()) { deck.ClearKeys(); } notifyIcon.Visible = false; Application.Exit(); Environment.Exit(1); }
static void Main(string[] args) { var devices = StreamDeck.GetDevices().ToList(); if (!devices.Any()) { Console.WriteLine("Could not find a StreamDeck."); Console.ReadKey(); return; } var deck = devices.First(); deck.Connect(); deck.SetBrightness(50); var renderer = new SampleRenderer(); Stopwatch sw = new Stopwatch(); sw.Start(); double lastTime = sw.Elapsed.TotalMilliseconds; Bitmap screen = new Bitmap(StreamDeck.FullScreenWidth, StreamDeck.FullScreenHeight); var graphics = Graphics.FromImage(screen); double targetFps = 60; double targetInterval = 1000 / targetFps; renderer.Init(screen.Width, screen.Height); deck.OnButtonDown += index => renderer.OnKeyDown(index); deck.OnButtonUp += index => renderer.OnKeyUp(index); while (true) { double now = sw.Elapsed.TotalMilliseconds; double dtMs = now - lastTime; double dt = dtMs / 1000; lastTime = now; renderer.Update(dt, screen, graphics); renderer.Render(dt, screen, graphics); deck.WriteScreenImage(screen); double delay = targetInterval - dtMs; if (delay > 0) { Thread.Sleep((int)delay); } } Console.WriteLine("StreamDeck found, press any key to exit."); Console.ReadKey(); deck.Disconnect(); }
/// <summary> /// Searches for a real classic stream deck or creates a virtual one. /// All examples are designed for the 5x3 classic StreamDeck. /// </summary> /// <returns></returns> public static IMacroBoard OpenBoard() { var realDeck = StreamDeck.EnumerateDevices(Hardware.StreamDeck).FirstOrDefault(); if (!(realDeck is null)) { return(realDeck.Open()); } return(null); // BoardFactory.SpawnVirtualBoard(Hardware.StreamDeck.Keys); }
static void Main(string[] args) { initializeIconBitmaps(); using (var s = StreamDeck.OpenDevice()) { s.KeyStateChanged += StreamDeckKeyHandler; startGame(s); Console.WriteLine("Press any key (on the keyboard) to exit Stream Deck demo."); Console.ReadKey(); } }
static void Main(string[] args) { //Open the Stream Deck device using (var deck = StreamDeck.OpenDevice()) { ConsoleWriteAndWait("Press any key to run System.Drawing example"); ExampleWithSystemDrawing(deck); ConsoleWriteAndWait("Press any key to run WPF FrameworkElement example"); ExampleWithWpfElement(deck); ConsoleWriteAndWait("Press any key to exit"); } }
private Business() { try { Deck = StreamDeck.FromHID(); Deck.KeyPressed += Deck_KeyPressed; } catch { //Application.Current.MainWindow.Dispatcher.BeginInvoke((Action)(() => //{ // MessageBox.Show("StreamDeck not connnedted."); //}), null); } }
static void Main(string[] args) { Console.CancelKeyPress += Console_CancelKeyPress; using (var deck = StreamDeck.OpenDevice()) { deck.SetBrightness(100); Console.WriteLine("Connected. Now press some keys on the Stream Deck."); deck.ClearKeys(); deck.KeyStateChanged += Deck_KeyPressed; Console.WriteLine("To close the console app press Ctrl + C"); exitSignal.WaitOne(); } }
public void LoadDevices() { IDeviceReader deviceReader = Container.Resolve <IDeviceReader>(); DeviceManager deviceManager = Container.Resolve <DeviceManager>(); DeviceModelList deviceModels = deviceReader.ReadDevices(); List <IStreamDeckRefHandle> deckRefHandles = StreamDeck.EnumerateDevices().ToList(); //TODO Add support for multuple devices var deviceModel = deviceModels.First(); foreach (IStreamDeckRefHandle streamDeckRefHandle in deckRefHandles) { deviceModel.Info.HardwareId = streamDeckRefHandle.DevicePath; IStreamDeckBoard board = streamDeckRefHandle.Open(); deviceManager.AddDevice(board, deviceModel); } }
public StreamDeckModel() { for (int i = 0; i < KeyCount; ++i) { ImageSources[i] = new WriteableBitmap(ImageWidth, ImageHeight, 96, 96, PixelFormats.Bgr24, null); } using (Graphics g = Graphics.FromImage(maskBitmap)) { g.Clear(System.Drawing.Color.Black); int diameter = 32; var arc = new Rectangle(0, 0, diameter, diameter); var path = new GraphicsPath(); // top left arc path.AddArc(arc, 180, 90); // top right arc arc.X = ImageWidth - diameter; path.AddArc(arc, 270, 90); // bottom right arc arc.Y = ImageHeight - diameter; path.AddArc(arc, 0, 90); // bottom left arc arc.X = 0; path.AddArc(arc, 90, 90); path.CloseFigure(); using (path) { g.FillPath(new System.Drawing.SolidBrush(System.Drawing.Color.White), path); } } StreamDeck = StreamDeck.Get(); StreamDeck.KeyChanged += StreamDeck_KeyChanged; StreamDeck.Open(); }
public static void Main(string[] args) { Console.CancelKeyPress += (sender, eArgs) => { _quitEvent.Set(); eArgs.Cancel = true; }; var deck = StreamDeck.OpenDevice(); InitDeck(deck); deck.ConnectionStateChanged += Deck_ConnectionStateChanged; deck.KeyStateChanged += Deck_KeyStateChanged; _quitEvent.WaitOne(); deck.SetBrightness(50); deck.ShowLogo(); }
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]); } } }
public DeckHandler() { //Load the default profile var path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/OpenStreamDeck/profiles/default.json"; try { CurrentProfile = ProfileManager.loadProfile(path); } catch (Exception e) { MessageBox.Show(String.Format("An error occurred while loading your default profile. Generating a new default profile. ({0})", e.Message)); if (CurrentProfile == null) { CurrentProfile = new Profile("Default"); ProfileManager.saveProfile(CurrentProfile); } } try { Deck = StreamDeck.FromHID(); } catch (Exception e) { //MessageBox.Show(String.Format("Cannot connect to StreamDeck ({0})", e.Message)); Debug.WriteLine("Cannot connect to StreamDeck {0}", e.Message); return; } Application.ApplicationExit += onApplicationExit; Deck.ClearKeys(); Deck.SetBrightness(DeckBrightness); Deck.KeyPressed += onKeyPressed; KeyPressedTimer = new System.Timers.Timer(); KeyPressedTimer.Interval = 10; KeyPressedTimer.Elapsed += onKeyHeld; CurrentPage = CurrentProfile.MainPage; PageStack = new Stack <Page>(); renderPage(); }
public static void DrawText(string text, int sdPos) { using (var deck = StreamDeck.OpenDevice()) { var key = KeyBitmap.FromGraphics(g => { g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; //Fill background black g.FillRectangle(Brushes.Black, 0, 0, deck.IconSize, deck.IconSize); //Write text to graphics var f = new Font("Arial", 24); g.DrawString(text, f, Brushes.White, new PointF(12, 20)); }); deck.SetKeyBitmap(sdPos, key); Thread.Sleep(500); } }
private void ClipboardChanged(object sender, EventArgs e) { if (_shouldCaptureImage) { var imageFromClipboard = Clipboard.GetImage(); if (imageFromClipboard != null) { var resizedImage = new TransformedBitmap(imageFromClipboard, new ScaleTransform(BUTTON_WIDTH / imageFromClipboard.PixelWidth, BUTTON_HEIGHT / imageFromClipboard.PixelHeight)); var bitmapEncoder = new PngBitmapEncoder(); bitmapEncoder.Frames.Add(BitmapFrame.Create(resizedImage)); var imageStream = new MemoryStream(); bitmapEncoder.Save(imageStream); var keybitmap = KeyBitmap.FromStream(imageStream); var clipboardItem = new ClipboardItem() { Bitmap = imageFromClipboard, KeyBitmap = keybitmap }; _clipboardItems.Enqueue(clipboardItem); while (_clipboardItems.Count > 5) { if (_clipboardItems.TryDequeue(out ClipboardItem item)) { } } var deck = StreamDeck.OpenDevice(); int i = 9; foreach (var clipItem in _clipboardItems) { deck.SetKeyBitmap(i--, clipItem.KeyBitmap); } } _shouldCaptureImage = false; } }
//===================================== // Epilepsiewarning! Flicking images //===================================== static void Main(string[] args) { //default (startup) value //press buttons on streamdeck to change method GetKeyBitmap = ReferenceImageFactory.GetChangingFilledImage; Console.CancelKeyPress += Console_CancelKeyPress; var availableFunctions = new Func <int, KeyBitmap>[] { GetBlank, ReferenceImageFactory.GetStableFilledImage, ReferenceImageFactory.GetChangingFilledImage, ReferenceImageFactory.GetStableLineImage, ReferenceImageFactory.GetChangingLineImage }; using (var deck = StreamDeck.OpenDevice()) { //setup StreamDeck button mapping keyFunctions = new Func <int, KeyBitmap> [deck.KeyCount]; for (int i = 0; i < deck.KeyCount; i++) { keyFunctions[i] = availableFunctions[i % availableFunctions.Length]; } deck.KeyStateChanged += Deck_KeyStateChanged; while (mode == 0) { for (int i = 0; i < deck.KeyCount; i++) { deck.SetKeyBitmap(i, GetKeyBitmap(i)); } } } }
public async Task <bool> Connect() { bool result = false; try { this.deck = StreamDeck.OpenDevice(); await this.ConnectionWrapper((deck) => { deck.ConnectionStateChanged -= Deck_ConnectionStateChanged; deck.KeyStateChanged -= Deck_KeyStateChanged; deck.ShowLogo(); deck.ConnectionStateChanged += Deck_ConnectionStateChanged; deck.KeyStateChanged += Deck_KeyStateChanged; result = true; return(Task.FromResult(0)); }); } catch (Exception ex) { Logger.Log(ex); } return(result); }
static void Main(string[] args) { using (var deck = StreamDeck.OpenDevice()) { var sw = Stopwatch.StartNew(); //Create random noise image var rnd = new Random(); var raw = new byte[72 * 72 * 3]; rnd.NextBytes(raw); var rndImage = KeyBitmap.FromRawBitmap(raw); deck.ClearKeys(); //Run a few million SetKeyBitmaps long cnt = 5_000_000; long i = cnt; while (--i > 0) { deck.SetKeyBitmap(7, rndImage); } var t = sw.Elapsed.TotalSeconds; var setKeyTime = t / cnt; //about 0.5µs on my machine Console.WriteLine((setKeyTime * 1000000.0) + " µs"); //Make sure that the test takes a least 3 seconds on your machine // -> change cnt! Console.WriteLine("Total Test time: " + t + " s"); Console.ReadKey(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { var deck = StreamDeck.OpenDevice(); InitDeck(deck); deck.ConnectionStateChanged += Deck_ConnectionStateChanged; deck.KeyStateChanged += Deck_KeyStateChanged; Application.Current.Exit += Current_Exit; _notifyIcon = new System.Windows.Forms.NotifyIcon { Icon = System.Drawing.SystemIcons.Application, Visible = true }; ShowInTaskbar = false; _notifyIcon.MouseDoubleClick += _notifyIcon_MouseDoubleClick; var windowClipboardManager = new ClipboardManager(this); windowClipboardManager.ClipboardChanged += ClipboardChanged; }
// Main program, which handles joystick initialization. static void Main(string[] args) { // Verify the vJoy driver is enabled. if (!VirtualJoystick.vJoyEnabled()) { return; } // Get the state of the requested device. VjdStat Status = VirtualJoystick.GetVJDStatus(Id); switch (Status) { case VjdStat.VJD_STAT_OWN: case VjdStat.VJD_STAT_FREE: break; case VjdStat.VJD_STAT_BUSY: case VjdStat.VJD_STAT_MISS: default: return; } ; // Acquire the target joystick. if ((Status == VjdStat.VJD_STAT_OWN) || ((Status == VjdStat.VJD_STAT_FREE) && (!VirtualJoystick.AcquireVJD(Id)))) { return; } // Open the Stream Deck device. var Deck = StreamDeck.OpenDevice(); // Set the brightness of the keys. Deck.SetBrightness(100); // Register the key pressed event handler. Deck.KeyStateChanged += StreamDeckKeyPressed; // Send the bitmap information to the device. Bitmap FullImage = new Bitmap(@"StreamDeckImage.png"); for (int i = 0; i < Deck.Keys.Count; i++) { int Left = (i % 5) * (72 + 16); int Top = (int)Math.Floor((double)i / 5) * (72 + 16); Rectangle CropArea = new Rectangle(Left, Top, 72, 72); buttonBitmaps.Add(FullImage.Clone(CropArea, FullImage.PixelFormat)); } // Infinitely loop, that way we can constantly receive key presses. while (true) { // TODO: Send OSC heartbeat message here. byte i = 0; foreach (Bitmap bitmap in buttonBitmaps) { Deck.SetKeyBitmap(i, KeyBitmap.Create.FromBitmap(bitmap)); i++; } Thread.Sleep(1000); } }
private void OnDisable() { StreamDeck.Remove(this); }
///***********************************************/// ///***********INITIALIZATION FUNCTIONS************/// ///***********************************************/// // Registers this class as a StreamDeck enabled class private void OnEnable() { StreamDeck.Add(this); }
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."); } } }
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); } } }