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); } }
private void DoPoll(object sender, EventArgs e) { _pollThreadRunning = true; var stroke = new ManagedWrapper.Stroke(); // Process Keyboard input for (var i = 1; i < 11; i++) { var isMonitoredKeyboard = _monitoredKeyboards.ContainsKey(i); while (ManagedWrapper.Receive(_deviceContext, i, ref stroke, 1) > 0) { if (isMonitoredKeyboard) { var blockingRequestedByUi = _monitoredKeyboards[i].ProcessUpdate(stroke); // Block for keyboard either blocks whole stroke or allows whole stroke through if (_blockingEnabled && (!_blockingControlledByUi || blockingRequestedByUi)) { continue; // Block input } } // Pass through stroke if (_fireStrokeOnThread) { var threadStroke = stroke; var deviceId = i; ThreadPool.QueueUserWorkItem(cb => ManagedWrapper.Send(_deviceContext, deviceId, ref threadStroke, 1)); } else { ManagedWrapper.Send(_deviceContext, i, ref stroke, 1); } } } // Process Mouse input // As a mouse stroke can contain multiple updates (buttons, movement etc) per stroke... // ...blocking is handled in ProcessUpdate, so if part of the stroke is blocked, it will be removed from the stroke for (var i = 11; i < 21; i++) { var isMonitoredMouse = _monitoredMice.ContainsKey(i); while (ManagedWrapper.Receive(_deviceContext, i, ref stroke, 1) > 0) { if (isMonitoredMouse) { stroke = _monitoredMice[i].ProcessUpdate(stroke); // Handle blocking - if all updates have been removed from stroke, do not bother to pass the stroke through if (stroke.mouse.x == 0 && stroke.mouse.y == 0 && stroke.mouse.state == 0) { continue; } } // Pass through stroke if (_fireStrokeOnThread) { var threadStroke = stroke; var deviceId = i; ThreadPool.QueueUserWorkItem(cb => ManagedWrapper.Send(_deviceContext, deviceId, ref threadStroke, 1)); } else { ManagedWrapper.Send(_deviceContext, i, ref stroke, 1); } } } _pollThreadRunning = false; }