简体   繁体   English

Windows 10中的键盘MSR和触摸屏键盘通用Windows应用程序之间的区别

[英]Differentiate between Keyboard MSR and touchscreen keyboard Universal windows application in windows 10

I have a xaml page in universal windows application in windows 10. The page contains a textbox. 我在Windows 10的通用Windows应用程序中有一个xaml页面。该页面包含一个文本框。 The application uses a keyboard MSR (Magnetic Stripe Reader) for swipping of cards. 该应用程序使用键盘MSR(磁条读取器)刷卡。

Now, when I have focus on textbox and I swipe the card in MSR, it prints all the data in the textbox. 现在,当我专注于文本框并在MSR中刷卡时,它将在文本框中打印所有数据。 BUt, I want to the user to just tap the text from touch screen keyboard and restrict it from MSR. BUt,我希望用户仅从触摸屏键盘上点击文本并从MSR限制它。

Please help. 请帮忙。

    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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM