コード例 #1
0
 protected override void ProcessEvent(object sender, StreamDeckSharp.KeyEventArgs arg)
 {
     if (arg.IsDown)
     {
         enabled = true;
     }
     else
     {
         enabled = false;
     }
 }
コード例 #2
0
        private void Deck_KeyStateChanged(object sender, StreamDeckSharp.KeyEventArgs e)
        {
            if (e.IsDown)
            {
                SyncContext.Post(async(state) =>
                {
                    if (sender is IStreamDeck deck)
                    {
                        if (e.Key == 0)
                        {
                            var path            = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                            mediaElement.Source = new Uri(System.IO.Path.Combine(path, "Resources/badum-tss.mp3"));
                            mediaElement.Play();
                            return;
                        }
                        if (e.Key == 1)
                        {
                            var path            = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                            mediaElement.Source = new Uri(System.IO.Path.Combine(path, "Resources/sad-trombone.mp3"));
                            mediaElement.Play();
                            return;
                        }
                        //if (e.Key == 5)
                        //{
                        //    for (ushort i = 0; i <= byte.MaxValue; i++)
                        //    {
                        //        deck.SetKeyBitmap(5, KeyBitmap.FromRGBColor((byte)i, (byte)(byte.MaxValue - i), (byte)i));
                        //        await Task.Delay(10);
                        //    }
                        //    return;
                        //}
                        if (e.Key > 4 && e.Key < 10)
                        {
                            try
                            {
                                Clipboard.SetImage(_clipboardItems.Reverse().ElementAt(e.Key - 5).Bitmap);
                                var inputSimulator = new InputSimulator();
                                inputSimulator.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LCONTROL, VirtualKeyCode.VK_V);
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine(ex.Message);
                            }
                            return;
                        }
                        if (e.Key == 4)
                        {
                            _shouldCaptureImage = true;
                            var inputSimulator  = new InputSimulator();
                            var modifiers       = new List <VirtualKeyCode>
                            {
                                VirtualKeyCode.LWIN,
                                VirtualKeyCode.LSHIFT
                            };
                            inputSimulator.Keyboard.ModifiedKeyStroke(modifiers, VirtualKeyCode.VK_S);
                            return;
                        }
                        //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);
                        //    deck.SetKeyBitmap(e.Key, keybitmap);
                        //}
                    }
                }, null);
                //switch (e.Key)
                //{
                //    case 0:
                //        Console.Write(e.Key);
                //        Console.WriteLine(" - Trondheim Ballklubb");
                //        break;
                //    case 1:
                //        Console.Write(e.Key);
                //        Console.WriteLine(" - Smiley");
                //        break;
                //    case 4:

                //        break;
                //    case 10:
                //        ArrayList selected = new ArrayList();
                //        //foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows())
                //        //{
                //        //    filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();
                //        //    if (filename.ToLowerInvariant() == "explorer")
                //        //    {
                //        //        Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                //        //        foreach (Shell32.FolderItem item in items)
                //        //        {
                //        //            selected.Add(item.Path);
                //        //        }
                //        //    }
                //        //}
                //        foreach (var file in selected)
                //        {
                //            Console.WriteLine(file);
                //        }
                //        break;
                //    case 11:


                //        //System.Windows.Clipboard
                //        break;
                //    case 14:
                //        if (sender is IStreamDeck deck)
                //        {
                //            Console.WriteLine("-----------------------");
                //            for (ushort i = 0; i <= byte.MaxValue; i++)
                //            {
                //                deck.SetKeyBitmap(14, KeyBitmap.FromRGBColor((byte)i, (byte)(byte.MaxValue - i), (byte)i));
                //                await Task.Delay(10);
                //                Console.WriteLine(i);
                //            }
                //        }
                //        break;
                //    default:
                //        Console.WriteLine(e.Key);
                //        break;
                //}
            }
        }