private static void Main() { KHOT_PARAMS hotInitParams = new KHOT_PARAMS(); // In the real world, you would want to filter for only *your* device(s). hotInitParams.PatternMatch.DeviceInterfaceGUID = "*"; // The PLUG_ALL_ON_INIT flag will force plug events for matching devices that are already connected. hotInitParams.Flags = KHOT_FLAG.PLUG_ALL_ON_INIT; hotInitParams.OnHotPlug = OnHotPlug; /* Instead of a callback you can send/post messages directly to a window handle. hotInitParams.UserHwnd = MyForm.Handle; hotInitParams.UserMessage = WM_USER_HOT_BASE; */ Console.WriteLine("Monitoring libusbK arrival/removal events."); Console.WriteLine("[PatternMatch]"); Console.WriteLine(hotInitParams.PatternMatch.ToString()); Console.WriteLine("Press [ENTER] to exit.."); while (Console.KeyAvailable) Console.ReadKey(true); // You may set your initial hot handle user context like this. // This example is using it to count connected devices and detect the first OnHotPlug event (Int32.MaxValue). AllKFunctions.LibK_SetDefaultContext(KLIB_HANDLE_TYPE.HOTK, new IntPtr(Int32.MaxValue)); // Start hot-plug detection. HotK hot = new HotK(ref hotInitParams); Console.ReadLine(); hot.Free(); }