Inheritance: IDisposable
Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            mHotParams.PatternMatch.DeviceInterfaceGUID = "*";
            
            // Set the Hwnd handle.
            mHotParams.UserHwnd = Handle;

            // Set the base user message.  This can be any value greater than or equal to 0x400
            mHotParams.UserMessage = WM_USER_HOT_BASE;
            
            // After initializing, send plug events for devices that are currently connected.
            mHotParams.Flags = KHOT_FLAG.PLUG_ALL_ON_INIT;

            // This will cause HotK to use PostMessage instead of SendMessage.
            mHotParams.Flags |= KHOT_FLAG.POST_USER_MESSAGE;

            mHotK = new HotK(ref mHotParams);
        }