Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using YeelightAPI;
- using Shortcut;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- namespace Yeelight
- {
- class Program
- {
- // --- SETTINGS
- static void settings()
- {
- firstModifier = Modifiers.Alt;
- secondModifier = Modifiers.Control;
- key = Keys.D8;
- lamps.Add(new Device("192.168.0.88"));
- lamps.Add(new Device("192.168.0.11"));
- lamps.Add(new Device("192.168.0.21"));
- }
- // --- END OF SETTINGS
- [DllImport("kernel32.dll")] public static extern IntPtr GetConsoleWindow();
- [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
- // --- VARIABLES
- static List<Device> lamps = new List<Device>();
- static DeviceGroup group;
- private static readonly HotkeyBinder _hotkeyBinder = new HotkeyBinder();
- static Modifiers firstModifier, secondModifier;
- static Keys key;
- // --- MAINNo
- static void Main(string[] args)
- {
- settings();
- var handle = GetConsoleWindow();
- ShowWindow(handle, 0);
- Console.Write("Connecting...");
- connect();
- Console.WriteLine(" Connected");
- _hotkeyBinder.Bind(firstModifier, key).To(HotkeyCallback);
- _hotkeyBinder.Bind(firstModifier | secondModifier, Keys.D8).To(HotkeyCallback2);
- Application.Run();
- }
- // --- CONNECTION
- static void connect()
- {
- group = new DeviceGroup();
- foreach (var item in lamps)
- {
- group.Add(item);
- }
- group.Connect();
- }
- static void toggle()
- {
- group.Toggle();
- }
- // --- HOTKEYS
- private static void HotkeyCallback()
- {
- toggle();
- }
- private static void HotkeyCallback2()
- {
- Console.WriteLine("Reconnecting");
- connect();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement