【问题标题】:Differentiate between Keyboard MSR and touchscreen keyboard Universal windows application in windows 10区分键盘 MSR 和触摸屏键盘 Windows 10 中的通用 Windows 应用程序
【发布时间】:2016-05-01 09:45:05
【问题描述】:

我在 windows 10 的通用 windows 应用程序中有一个 xaml 页面。该页面包含一个文本框。该应用程序使用键盘 MSR(磁条阅读器)来刷卡。

现在,当我专注于文本框并在 MSR 中刷卡时,它会打印文本框中的所有数据。但是,我希望用户只需点击触摸屏键盘上的文本并将其限制在 MSR 中。

请帮忙。

【问题讨论】:

    标签: c# xaml keyboard windows-10-universal magnetic-cards


    【解决方案1】:
        private DispatcherTimer _handledTimer;
    
        private bool _isHandled = false;
    
        private bool _isShift = false;
    
        private void txtEmailKeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
        {
            if (e.Key == VirtualKey.Shift)
            {
                _isShift = true;
            }
            else
            {
                if (ToChar(e.Key, _isShift))
                {
                    _isHandled = true;
                    StartDispatcher();
                }
                _isShift = false;
            }
            e.Handled = _isHandled;
        }
    
    
        public void StartDispatcher()
        {
            if (_handledTimer == null)
            {
                _handledTimer = new DispatcherTimer();
                _handledTimer.Interval = new TimeSpan(0, 0, 1);
                _handledTimer.Tick += handledTimerTick;
            }
            _handledTimer.Stop();
            _handledTimer.Start();
        }
    
        private void handledTimerTick(object sender, object e)
        {
            _handledTimer.Stop();
            _handledTimer = null;
            _isHandled = false;
        }
    
        private bool ToChar(VirtualKey key, bool shift)
        {
            bool hasSpecificChar = false;
            // look for %
            if (53 == (int)key && shift)
            {
                hasSpecificChar = true;
            }
    
            // look for ';'
            if (186 == (int)key)
            {
                hasSpecificChar = true;
            }
            return hasSpecificChar;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      • 2015-11-22
      • 1970-01-01
      • 2018-11-03
      • 2016-07-13
      • 2014-01-25
      相关资源
      最近更新 更多