簡體   English   中英

Windows 10中的鍵盤MSR和觸摸屏鍵盤通用Windows應用程序之間的區別

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

我在Windows 10的通用Windows應用程序中有一個xaml頁面。該頁面包含一個文本框。 該應用程序使用鍵盤MSR(磁條讀取器)刷卡。

現在,當我專注於文本框並在MSR中刷卡時,它將在文本框中打印所有數據。 BUt,我希望用戶僅從觸摸屏鍵盤上點擊文本並從MSR限制它。

請幫忙。

    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