private void KeyboardListener_s_KeyEventHandler(object sender, EventArgs e) { KeyboardListener.UniversalKeyEventArgs eventArgs = (KeyboardListener.UniversalKeyEventArgs)e; if (eventArgs.m_Msg == 256) { //Console.Out.WriteLine(string.Format("Key = {0} Msg = {1} Text = {2}", eventArgs.m_Key, eventArgs.m_Msg, eventArgs.KeyData)); TimeSpan elapsed = (DateTime.Now - _lastKeystroke); if (elapsed.TotalMilliseconds > (int)Settings.Default.BarcodeSpeed) { _barcode.Clear(); } if (Settings.Default.BarcodeOnlyNumber) { if (char.IsNumber((char)eventArgs.KeyData)) { _barcode.Add((char)eventArgs.KeyData); } } else { if (char.IsNumber((char)eventArgs.KeyData) || char.IsLetter((char)eventArgs.KeyData)) { _barcode.Add((char)eventArgs.KeyData); } } string barcode = new string(_barcode.ToArray()); if (eventArgs.m_Key == 13 && _barcode.Count > 0 && barcode.Length >= Settings.Default.BarcodeMinlength) { foreach (var item in Settings.Default.QRCodeIgnore) { if (barcode.StartsWith(item)) { barcode = barcode.Replace(item, string.Empty); } } manuelBarcods.Add(barcode); lblManuelBarcode.Text = manuelBarcods.Count.ToString(); lblManuelBarcode.Visible = true; Logger.GetInstance().Info("Okunan Perakende Barkodu: " + barcode); _barcode.Clear(); } _lastKeystroke = DateTime.Now; } }
private void KeyboardListener_s_KeyEventHandler(object sender, EventArgs e) { try { KeyboardListener.UniversalKeyEventArgs eventArgs = (KeyboardListener.UniversalKeyEventArgs)e; KeyboardEventInfo kei = new KeyboardEventInfo(eventArgs); if (Config.Current.IgnoredKeys.Contains((int)eventArgs.m_Key)) { return; } WindowInfo curWindow = new WindowInfo(GetForegroundWindow()); if (_Windows.Contains(curWindow) == true) { if (Active == true) { //WriteLog(string.Format("SEND : {0} - {1:X} - {2:X}", ((Keys) kei.m_Key).ToString(), kei.m_Msg, kei.lParam)); foreach (WindowInfo i in _Windows) { if (i.Equals(curWindow) == false) { kei.PostMessage(i.Handle); } } } if (_Recorder != null && _Recorder.Recording == true) { //WriteLog(string.Format("RECORD : {0} - {1:X} - {2:X}", ((Keys)kei.m_Key).ToString(), kei.m_Msg, kei.lParam)); _Recorder.Add(kei); } } } catch (Exception ex) { Utils.ShowError(ex); } }