성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>USB/IP PROJECT를 이용해 C#으로 USB Keyboard + Mouse 가상 장치 만들기</h1> <p> 이미 지난 글에서 설명한,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > USB/IP PROJECT를 이용해 C#으로 USB Keyboard 가상 장치 만들기 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12216'>https://www.sysnet.pe.kr/2/0/12216</a> </pre> <br /> 내용에다 Raspberry PI Zero로 다뤘던 키보드와 마우스의 Report Descriptor를 그대로 가져다 합치면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 키보드 및 마우스로 쓰는 방법 (절대 좌표, 상대 좌표, 휠) ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/11369'>https://www.sysnet.pe.kr/2/0/11369</a> </pre> <br /> 아래와 같은 C# 소스 코드로 가상 마우스와 키보드를 구현할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > using HelperExtension; using System; using System.Diagnostics; using System.Threading; using UsbipDevice; namespace cs_hid_keyboardmouse { class Program { static void Main(string[] args) { Console.WriteLine("cs-hid-keyboardmouse"); bool waitLocalHost = true; if (args.Length >= 1) { if (args[0] == "-w") { waitLocalHost = false; } } int cxScreen = SafeMethods.GetSystemMetrics(SystemMetric.SM_CXVIRTUALSCREEN); int cyScreen = SafeMethods.GetSystemMetrics(SystemMetric.SM_CYVIRTUALSCREEN); Console.WriteLine($"CX: {cxScreen}"); Console.WriteLine($"CY: {cyScreen}"); byte[] reportBuffer = KeyboardMouseDescriptors.Report; using (Usbip device = new Usbip(UsbDescriptors.Device, KeyboardMouseDescriptors.Hid, reportBuffer)) { MouseDevice mouse = new MouseDevice(device, reportBuffer, cxScreen, cyScreen); KeyboardDevice keyboard = new KeyboardDevice(device, reportBuffer); device.Run(); if (waitLocalHost == true) { Thread usbipServer = new Thread(usbipServer_Run); usbipServer.IsBackground = true; usbipServer.Start(); } KeyboardMouseTest(mouse, keyboard); } } private static void usbipServer_Run(object obj) { foreach (Process process in Process.GetProcessesByName("usbip")) { process.Kill(); } // usbip attach -r 127.0.0.1 -b 1-1 Process.Start("usbip", "attach -r 127.0.0.1 -b 1-1"); } private static void KeyboardMouseTest(MouseDevice mouse, KeyboardDevice keyboard) { Console.WriteLine("Wait for usbip..."); while (true) { Console.Write("."); if (mouse.Connected == true) { break; } Thread.Sleep(1000); } bool mouseMode = false; while (true) { Console.Write(((mouseMode == true) ? "Mouse" : "Keyboard") + "> "); string text = Console.ReadLine(); if (text == "quit") { break; } if (text == "--mode") { mouseMode ^= mouseMode; continue; } Thread.Sleep(2000); if (mouseMode == true) { mouse.SendText(text); } else { keyboard.SendText(text); } } } } } </pre> <br /> 오~~~ 멋지죠? ^^ 관련 소스 코드는 다음의 github repo에 모두 올려놓았습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > USBIP-Virtual-USB-Device/dotnet/cs-hid-keyboardmouse/ ; <a target='tab' href='https://github.com/stjeong/USBIP-Virtual-USB-Device/tree/master/dotnet/cs-hid-keyboardmouse'>https://github.com/stjeong/USBIP-Virtual-USB-Device/tree/master/dotnet/cs-hid-keyboardmouse</a> </pre> <br /> 아울러 UsbipDevice 타입은 NuGet에도 등록했으니 참고하시고!<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > UsbipDevice ; <a target='tab' href='https://www.nuget.org/packages/UsbipDevice/'>https://www.nuget.org/packages/UsbipDevice/</a> PM> Install-Package UsbipDevice -Version 1.0.4 </pre> <br /> 간간이 다음의 글도 한 번 보는 것도 도움이 될 것입니다. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > USB in a NutShell ; <a target='tab' href='https://www.beyondlogic.org/usbnutshell/usb1.shtml'>https://www.beyondlogic.org/usbnutshell/usb1.shtml</a> </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1321
(왼쪽의 숫자를 입력해야 합니다.)