コード例 #1
0
ファイル: Program.cs プロジェクト: Logitech/hackzurich2019
 static int ShowSpyConfig(SpyConfig sp)
 {
     if (sp != null)
     {
         Console.WriteLine(sp.unitId + ": buttons:" + sp.spyButtons + ", keys:" + sp.spyKeys + ", pointer:" + sp.spyPointer + ", thumbWheel:" + sp.spyThumbWheel + ", wheel:" + sp.spyWheel);
     }
     return(0);
 }
コード例 #2
0
ファイル: LogiDevMon.cs プロジェクト: Logitech/hackzurich2019
        public static void SetSpyConfig(SpyConfig newSpyConfig)
        {
            var msg = new { verb = "set", path = "spyConfig", args = new { value = newSpyConfig } };
            var jsonString = JsonConvert.SerializeObject(msg);

            ws = new WebSocket(devmonUrl);

            ws.Connect();
            ws.Send(jsonString);
            ws.Close();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Logitech/hackzurich2019
        static int ShowEvents(object payload, WebSocket ws)
        {
            string jsonString = JsonConvert.SerializeObject(payload);

            Console.WriteLine(eventsCount + ": " + jsonString);
            eventsCount--;

            if (eventsCount < 1)
            {
                ws.Close();

                Console.WriteLine("Stop spying keyboard keys");
                SpyConfig spyconfig = new SpyConfig
                {
                    unitId  = LogiDevMon.devices[0].unitId,
                    spyKeys = false
                };

                LogiDevMon.SetSpyConfig(spyconfig);
            }
            return(0);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Logitech/hackzurich2019
        static void Main(string[] args)
        {
            LogiDevMon.GetDevices(ListDevices);

            Thread.Sleep(1500);

            Console.WriteLine();

            if (LogiDevMon.devices.Count > 0 && keyboardIndex != -1)
            {
                Console.WriteLine("SpyConfig for: " + LogiDevMon.devices[keyboardIndex].name);
                LogiDevMon.GetSpyConfig(LogiDevMon.devices[keyboardIndex].unitId, ShowSpyConfig);

                Thread.Sleep(1000);

                SpyConfig spyconfig = new SpyConfig
                {
                    unitId  = LogiDevMon.devices[keyboardIndex].unitId,
                    spyKeys = true
                };

                Console.WriteLine("\nSpy keyboard keys");
                LogiDevMon.SetSpyConfig(spyconfig);
                Thread.Sleep(1000);
                LogiDevMon.GetSpyConfig(LogiDevMon.devices[keyboardIndex].unitId, ShowSpyConfig);
                Thread.Sleep(1000);

                Console.WriteLine("\nRead Key events");
                LogiDevMon.ReadEvents(ShowEvents);
            }
            else
            {
                Console.WriteLine("No keyboard detected, press any key to exit...");
            }

            Console.ReadKey(true);
        }
コード例 #5
0
ファイル: LogiDevMon.cs プロジェクト: Logitech/hackzurich2019
        public static void GetSpyConfig(UInt32 _unitId, Func<SpyConfig, int> callback)
        {
            var msg = new { verb = "get", path = "spyConfig", args = new {unitId = _unitId} };
            var jsonString = JsonConvert.SerializeObject(msg);

            ws = new WebSocket(devmonUrl);

            ws.OnMessage += (sender, e) =>
            {
                SpyConfig spyConfig = null;

                Dictionary<string, object> objectData = JsonConvert.DeserializeObject<Dictionary<string, object>>(e.Data);
                if ((bool)objectData["success"])
                {
                    Newtonsoft.Json.Linq.JObject o = (Newtonsoft.Json.Linq.JObject)objectData["value"];
                    spyConfig = o.ToObject<SpyConfig>();
                }
                ws.Close();
                callback(spyConfig);
            };

            ws.Connect();
            ws.Send(jsonString);
        }
コード例 #6
0
        static int ShowEvents(object payload, WebSocket ws)
        {
            string jsonString = JsonConvert.SerializeObject(payload);

            Console.WriteLine(eventsCount + ": " + jsonString);

            int keyPressed = (int)JsonConvert.DeserializeObject <keyPressed>(jsonString).cid1;

            switch (keyPressed)
            {
            case 199:
                Console.WriteLine("F1");
                break;

            case 200:
                Console.WriteLine("F2");
                break;

            case 224:
                Console.WriteLine("F3");
                break;

            case 225:
                Console.WriteLine("F4");
                break;

            case 110:
                Console.WriteLine("F5");
                break;
            }

            eventsCount--;

            if (eventsCount < 1)
            {
                ws.Close();

                Console.WriteLine("Stop spying keyboard keys");
                SpyConfig spyconfig = new SpyConfig
                {
                    unitId  = LogiDevMon.devices[0].unitId,
                    spyKeys = false
                };

                SpecialKey F1 = new SpecialKey
                {
                    unitId    = LogiDevMon.devices[0].unitId,
                    controlId = 199,    //F1
                    divert    = false,
                    persist   = false
                };


                SpecialKey F2 = new SpecialKey
                {
                    unitId    = LogiDevMon.devices[0].unitId,
                    controlId = 200,    //F2
                    divert    = false
                };

                SpecialKey F3 = new SpecialKey
                {
                    unitId    = LogiDevMon.devices[0].unitId,
                    controlId = 224,    //F3
                    divert    = false
                };

                SpecialKey F4 = new SpecialKey
                {
                    unitId    = LogiDevMon.devices[0].unitId,
                    controlId = 225,    //F4
                    divert    = false
                };

                SpecialKey F5 = new SpecialKey
                {
                    unitId    = LogiDevMon.devices[0].unitId,
                    controlId = 110,    //F5
                    divert    = false
                };

                LogiDevMon.SetSpyConfig(spyconfig);
                LogiDevMon.SetSpecialKey(F1);
                LogiDevMon.SetSpecialKey(F2);
                LogiDevMon.SetSpecialKey(F3);
                LogiDevMon.SetSpecialKey(F4);
                LogiDevMon.SetSpecialKey(F5);
            }
            return(0);
        }