private bool TryFindKeyboardDeviceId(out int deviceId) { for (int i = 1; i <= 20; i++) { if (ManagedWrapper.IsKeyboard(i) <= 0) { continue; } string name = ManagedWrapper.GetHardwareStr(context, i); if (!string.IsNullOrWhiteSpace(name)) { // Console.WriteLine($"Found device\nid = {i}\nname = {name}"); deviceId = i; return(true); } } deviceId = -1; return(false); }
public void EchoInput() { Console.WriteLine("Echo mode activated. Press Ctrl-C to exit."); Console.WriteLine("code\tstate\tname"); ManagedWrapper.SetFilter(context, ManagedWrapper.IsKeyboard, ManagedWrapper.Filter.All); try { while (true) { int device; var stroke = new ManagedWrapper.Stroke(); if (ManagedWrapper.Receive(context, device = ManagedWrapper.WaitWithTimeout(context, 5), ref stroke, 1) > 0) { if (ManagedWrapper.IsKeyboard(device) > 0) { int scancode = stroke.key.code; if ((stroke.key.state & 2) != 0) { scancode += 256; } Console.WriteLine($"{stroke.key.code}\t" + $"{(ManagedWrapper.KeyState) stroke.key.state}\t" + $"{KeyNameHelper.GetNameFromScanCode(scancode)}"); ManagedWrapper.Send(context, device, ref stroke, 1); } } } } catch (Exception e) { Console.Error.WriteLine(e); } }
public void RefreshConnectedDevices() { _deviceHandleToId = new Dictionary <string, List <int> >(); _deviceReports = new List <DeviceReport>(); string handle; for (var i = 1; i < 11; i++) { if (ManagedWrapper.IsKeyboard(i) != 1) { continue; } handle = ManagedWrapper.GetHardwareStr(_deviceContext, i, 1000); if (handle == "") { continue; } int vid = 0, pid = 0; GetVidPid(handle, ref vid, ref pid); var name = ""; if (vid != 0 && pid != 0) { name = DeviceHelper.GetDeviceName(vid, pid); } if (name == "") { name = handle; } handle = $@"Keyboard\{handle}"; if (!_deviceHandleToId.ContainsKey(handle)) { _deviceHandleToId.Add(handle, new List <int>()); } var instance = _deviceHandleToId[handle].Count; _deviceHandleToId[handle].Add(i); name = $"K: {name}"; if (instance > 0) { name += $" #{instance + 1}"; } _deviceReports.Add(new DeviceReport { DeviceName = name, DeviceDescriptor = new DeviceDescriptor { DeviceHandle = handle, DeviceInstance = instance }, Nodes = new List <DeviceReportNode> { _keyboardList } }); //Log(String.Format("{0} (Keyboard) = VID: {1}, PID: {2}, Name: {3}", i, vid, pid, name)); } for (var i = 11; i < 21; i++) { if (ManagedWrapper.IsMouse(i) != 1) { continue; } handle = ManagedWrapper.GetHardwareStr(_deviceContext, i, 1000); if (handle == "") { continue; } int vid = 0, pid = 0; GetVidPid(handle, ref vid, ref pid); var name = ""; if (vid != 0 && pid != 0) { name = DeviceHelper.GetDeviceName(vid, pid); } if (name == "") { name = handle; } handle = $@"Mouse\{handle}"; if (!_deviceHandleToId.ContainsKey(handle)) { _deviceHandleToId.Add(handle, new List <int>()); } var instance = _deviceHandleToId[handle].Count; _deviceHandleToId[handle].Add(i); name = $"M: {name}"; if (instance > 0) { name += $" #{instance + 1}"; } _deviceReports.Add(new DeviceReport { DeviceName = name, DeviceDescriptor = new DeviceDescriptor { DeviceHandle = handle, DeviceInstance = instance }, Nodes = new List <DeviceReportNode> { _mouseButtonList, StaticData.MouseAxisList } }); //Log(String.Format("{0} (Mouse) = VID/PID: {1}", i, handle)); //Log(String.Format("{0} (Mouse) = VID: {1}, PID: {2}, Name: {3}", i, vid, pid, name)); } _providerReport = new ProviderReport { Title = "Interception (Core)", Description = "Supports per-device Keyboard and Mouse Input/Output, with blocking\nRequires custom driver from http://oblita.com/interception", API = "Interception", ProviderDescriptor = _providerDescriptor, Devices = _deviceReports }; }