예제 #1
0
        protected override void WndProc(ref Message message)
        {
            switch (message.Msg)
            {
            case Win32.WM_INPUT:
            {
                _keyboardDriver.ProcessRawInput(message.LParam);
                _mouseDriver.ProcessRawInput(message.LParam);
            }
            break;

            case Win32.WM_USB_DEVICECHANGE:
            {
                //0x0007 DBT_DEVNODES_CHANGED
                if ((((int)message.WParam) & 0x0007) == 0x0007)
                {
                    Debug.WriteLine("USB Device Arrival / Removal");
                    _keyboardDriver.EnumerateDevices();
                    _mouseDriver.EnumerateDevices();

                    if (DevicesChanged != null)
                    {
                        DevicesChanged(this);
                    }
                }
            }
            break;
            }
            base.WndProc(ref message);
        }
예제 #2
0
        public RawInput(IntPtr parentHandle, bool captureOnlyInForeground)
        {
            AssignHandle(parentHandle);

            _keyboardDriver = new RawKeyboard(parentHandle, captureOnlyInForeground);
            _keyboardDriver.EnumerateDevices();
            _devNotifyHandle = RegisterForDeviceNotifications(parentHandle);
        }
예제 #3
0
        public RawInput(IntPtr parentHandle)
        {
            AssignHandle(parentHandle);

            _keyboardDriver = new RawKeyboard(parentHandle);
            _keyboardDriver.EnumerateDevices();
            _devNotifyHandle = RegisterForDeviceNotifications(parentHandle);
        }
예제 #4
0
        public RawInput(IntPtr parentHandle)
        {
            AssignHandle(parentHandle);

            _keyboardDriver = new RawKeyboard(parentHandle);
            _keyboardDriver.EnumerateDevices();
            _devNotifyHandle = RegisterForDeviceNotifications(parentHandle);
        }
예제 #5
0
        public RawInput(IntPtr parentHandle, bool captureOnlyInForeground)
        {
            AssignHandle(parentHandle);

            _keyboardDriver = new RawKeyboard(parentHandle, captureOnlyInForeground);
            _keyboardDriver.EnumerateDevices();
            _devNotifyHandle = RegisterForDeviceNotifications(parentHandle);
        }
예제 #6
0
        protected override void WndProc(ref Message message)
        {
            switch (message.Msg)
            {
            case Win32.WM_INPUT:
            {
                _keyboardDriver.ProcessRawInput(message.LParam);
            }
            break;

            case Win32.WM_USB_DEVICECHANGE:
            {
                Debug.WriteLine("USB Device Arrival / Removal");
                _keyboardDriver.EnumerateDevices();
            }
            break;
            }

            base.WndProc(ref message);
        }
예제 #7
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (this.dispatcher == null)
            {
                this.dispatcher = this.Dispatcher;
                this.dispatcherHooks = this.dispatcher.Hooks;
            }

            WindowInteropHelper wndHelper = new WindowInteropHelper(this);
            IntPtr wpfHwnd = wndHelper.Handle;

            _keyboardDriver = new RawKeyboard(wpfHwnd);
            _keyboardDriver.EnumerateDevices();
            _devNotifyHandle = RegisterForDeviceNotifications(wpfHwnd);

            System.Windows.Interop.ComponentDispatcher.ThreadFilterMessage +=
                    new System.Windows.Interop.ThreadMessageEventHandler(ComponentDispatcher_ThreadFilterMessage);
            System.Windows.Interop.ComponentDispatcher.ThreadPreprocessMessage +=
                    new System.Windows.Interop.ThreadMessageEventHandler(ComponentDispatcher_ThreadPreprocessMessage);

            this.KeyPressed += new RawKeyboard.DeviceEventHandler(OnKeyPressed);
        }
예제 #8
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (this.dispatcher == null)
            {
                this.dispatcher = this.Dispatcher;
            }

            //获取本窗体的句柄
            WindowInteropHelper wndHelper = new WindowInteropHelper(this);
            _wpfHwnd = wndHelper.Handle;

            _keyboardDriver = new RawKeyboard(_wpfHwnd);
            _keyboardDriver.CaptureOnlyIfTopMostWindow = false;
            _keyboardDriver.EnumerateDevices();

            //之所以不在 WndProc 进行消息的拦截,是因为···在 WPF 中,消息到 WndProc 的时候,都已经显示在界面上了
            //当然,在 WinForm 程序上还是有效的,所以在这里,就 在这个消息中截取
            System.Windows.Interop.ComponentDispatcher.ThreadFilterMessage +=
                    new System.Windows.Interop.ThreadMessageEventHandler(ComponentDispatcher_ThreadFilterMessage);

            DisplayMemory();
            Console.WriteLine();
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("--- New Listener #{0} ---", i + 1);

                var listener = new TestListener(new TestClassHasEvent());
                ////listener = null; //可有可无    

                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                DisplayMemory();

            }

            byte[] b = new byte[10];
            b[11] = 1;  
            for (int i = 0; i < 11; i++ )
            {
                b[i] = (byte)i;
            }

            var file = new FileStream("DeviceAudit.txt", FileMode.Create, FileAccess.Write);
            var sw = new StreamWriter(file);

            sw.WriteLine("1234-----");
            sw.WriteLine(Marshal.GetLastWin32Error());
//             sw.Flush();
//             sw.Close();
//             file.Close();


        }
예제 #9
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (this.dispatcher == null)
            {
                this.dispatcher = this.Dispatcher;
            }

            //获取本窗体的句柄
            WindowInteropHelper wndHelper = new WindowInteropHelper(this);
            _wpfHwnd = wndHelper.Handle;

            _keyboardDriver = new RawKeyboard(_wpfHwnd);
            _keyboardDriver.CaptureOnlyIfTopMostWindow = false;
            _keyboardDriver.EnumerateDevices();

            //之所以不在 WndProc 进行消息的拦截,是因为···在 WPF 中,消息到 WndProc 的时候,都已经显示在界面上了
            //当然,在 WinForm 程序上还是有效的,所以在这里,就 在这个消息中截取
            System.Windows.Interop.ComponentDispatcher.ThreadFilterMessage +=
                    new System.Windows.Interop.ThreadMessageEventHandler(ComponentDispatcher_ThreadFilterMessage);
        }