public KeyboardDevice(Usbip device, byte[] reportDescriptor) { _device = device; _reportDescriptor = reportDescriptor; _hasReportId = ReportDescEnumerator.HasReportId(_reportDescriptor); }
internal List <byte[]> ConvertToMouseCommand(string txt) { List <byte[]> list = new List <byte[]>(); string[] tokens = txt.Split(' '); for (int i = 0; i < tokens.Length; i++) { byte reportId = 0; byte[] keyDown = TokenToCommand(tokens, ref i, out reportId); if (keyDown == null) { continue; } list.Add(keyDown); byte[] keyUp = new byte[ReportDescEnumerator.GetReportSize(_reportDescriptor, reportId)]; keyUp[0] = reportId; list.Add(keyUp); } return(list); }
public MouseDevice(Usbip device, byte [] reportDescriptor, int screenSizeX, int screenSizeY) { _device = device; _reportDescriptor = reportDescriptor; _screenSizeX = screenSizeX; _screenSizeY = screenSizeY; _hasReportId = ReportDescEnumerator.HasReportId(_reportDescriptor); }
public static bool HasReportId(byte[] buffer) { ReportDescEnumerator desc = new ReportDescEnumerator(buffer); foreach (ReportItem item in desc) { if (item.Key == ReportDescKey.REPORT_ID) { return(true); } } return(false); }
byte [] GetBuffer(byte reportId) { int bufferSize = ReportDescEnumerator.GetReportSize(_reportDescriptor, reportId); if (bufferSize > 8) { bufferSize = 8; } byte[] buffer = new byte[bufferSize]; buffer[0] = reportId; return(buffer); }
public byte[] RelativeBuffer(byte reportId, byte button, byte xPos, byte yPos) { byte[] buffer = new byte[ReportDescEnumerator.GetReportSize(_reportDescriptor, reportId)]; int idx = 0; if (reportId != 0) { buffer[idx++] = reportId; } buffer[idx++] = button; buffer[idx++] = xPos; buffer[idx++] = yPos; return(buffer); }
public byte[] AbsoluteBuffer(byte reportId, int xPos, int yPos, byte wheel) { int x = (int)(xPos * 32767 / _screenSizeX); int y = (int)(yPos * 32767 / _screenSizeY); byte[] buffer = new byte[ReportDescEnumerator.GetReportSize(_reportDescriptor, reportId)]; buffer[0] = reportId; buffer[1] = (byte)(x & 0xff); buffer[2] = (byte)((x & 0xff00) >> 8); buffer[3] = (byte)(y & 0xff); buffer[4] = (byte)((y & 0xff00) >> 8); if (buffer.Length > 5) { buffer[5] = wheel; } return(buffer); }
public static int GetReportSize(byte[] buffer, int reportId) { ReportDescEnumerator desc = new ReportDescEnumerator(buffer); int bitCount = 0; int currentReportId = 0; int collectionDepth = 0; foreach (ReportItem item in desc) { if (item.Key == ReportDescKey.REPORT_SIZE) { ReportItem nextItem = desc.PeekNext(); if (nextItem.Key == ReportDescKey.REPORT_COUNT) { bitCount += (item.Data8 * nextItem.Data8); } } else if (item.Key == ReportDescKey.REPORT_COUNT) { ReportItem nextItem = desc.PeekNext(); if (nextItem.Key == ReportDescKey.REPORT_SIZE) { bitCount += (item.Data8 * nextItem.Data8); } } if (item.Key == ReportDescKey.COLLECTION) { collectionDepth++; continue; } else if (item.Key == ReportDescKey.END_COLLECTION) { collectionDepth--; } if (item.Key == ReportDescKey.REPORT_ID) { currentReportId = item.Data8; bitCount += 8; continue; } if (collectionDepth == 0) { if (bitCount == 0) { continue; } if (currentReportId == reportId) { return(bitCount / 8); } bitCount = 0; } } return(bitCount / 8); }