public RawInput(IntPtr parentHandle) { AssignHandle(parentHandle); _keyboardDriver = new RawKeyboard(parentHandle); _keyboardDriver.EnumerateDevices(); _devNotifyHandle = RegisterForDeviceNotifications(parentHandle); }
public RawInput(IntPtr parentHandle, bool captureOnlyInForeground) { AssignHandle(parentHandle); _keyboardDriver = new RawKeyboard(parentHandle, captureOnlyInForeground); _keyboardDriver.EnumerateDevices(); _devNotifyHandle = RegisterForDeviceNotifications(parentHandle); }
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); }
private void Window_Loaded(object sender, RoutedEventArgs e) { RawKeyboard rk = new RawKeyboard(); kbList = rk.DeviceNameList(); SelectedDeviceName = kbList[0]; //Init Keyboard AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; _rawinput = new RawInput(Process.GetCurrentProcess().MainWindowHandle, CaptureOnlyInForeground); _rawinput.AddMessageFilter(); // Adding a message filter will cause keypresses to be handled Win32.DeviceAudit(); // Writes a file DeviceAudit.txt to the current directory _rawinput.KeyPressed += OnKeyPressed; // 이미지 백그라운드 설정 this.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), System.AppDomain.CurrentDomain.BaseDirectory + @"\skin.jpg"))); // 창 사이즈 조절용 orginalWidth = this.Width; originalHeight = this.Height; if (this.WindowState == WindowState.Maximized) { ChangeSize(this.ActualWidth, this.ActualHeight); } this.SizeChanged += new SizeChangedEventHandler(Window_SizeChanged); //바코드파일 읽어서 리스트로 가지고 있기 string path = System.AppDomain.CurrentDomain.BaseDirectory + @"\barcode.txt"; using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { using (StreamReader sr = new StreamReader(fs, Encoding.Default)) { string line; while ((line = sr.ReadLine()) != null) { if (!string.IsNullOrEmpty(line.Trim())) { //객체 생성해서 넣기 string[] data = line.Split(';'); if (!list.ContainsKey(data[0])) list.Add(data[0], new Item { Barcode = data[0], Name = data[1], Amount = Convert.ToInt32(data[2].Replace(",", string.Empty)), Count = 1 }); } } } } //샘플 데이터 삽입 //int cnt = 0; //foreach (KeyValuePair<string, Item> i in list) //{ // if (cnt > 50) // { // break; // } // cartItems.Add(i.Value.Barcode, new Item { Barcode = i.Value.Barcode, Amount = i.Value.Amount, Name = i.Value.Name, Count = 1 }); // cnt++; //} lvCart.ItemsSource = cartItems; UpdateTotalAmount(); //버튼 텍스트 변경 Label lbAdd = (Label)btnADD.Template.FindName("Content", btnADD); lbAdd.Content = "추가+"; Label lbRemove = (Label)btnREMOVE.Template.FindName("Content", btnREMOVE); lbRemove.Content = "제거-"; Label lbInit = (Label)btnInit.Template.FindName("Content", btnInit); lbInit.Content = "초기화"; Label lbCard = (Label)btnCard.Template.FindName("Content", btnCard); lbCard.Content = "카드결제"; Label lbCash = (Label)btnCash.Template.FindName("Content", btnCash); lbCash.Content = "현금결제"; btnADD.IsEnabled = false; }
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(); }
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); }