首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >区分键盘MSR和触摸屏键盘windows 10中的通用windows应用程序

区分键盘MSR和触摸屏键盘windows 10中的通用windows应用程序
EN

Stack Overflow用户
提问于 2016-01-25 14:45:13
回答 1查看 108关注 0票数 0

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

现在,当我将焦点放在textbox上并在MSR中刷卡时,它会打印textbox中的所有数据。BUt,我想让用户只点击来自触摸屏键盘的文本,并限制它从MSR。

请帮帮忙。

EN

回答 1

Stack Overflow用户

发布于 2016-02-04 14:28:50

代码语言:javascript
复制
    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;
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34986568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档