简体   繁体   English

如何检查屏幕键盘的Ctrl键是否被按下?

[英]How can I check for the on screen keyboard's Ctrl key being pressed down?

I currently have this code: 我目前有这个代码:

        DataGrid.SelectionChanged += new SelectionChangedEventHandler(DataGrid_SelectionChanged);

        private void DataGrid_SelectionChanged(object sender, EventArgs e)
        {
            if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
            {
                //do stuff
            }
        }

The code checks for the Ctrl button when the selection in a data grid changes which works fine for detecting the Ctrl key for normal physical keys but when I use the on screen keyboard and press down the Ctrl key it doesn't register in my program. 当数据网格中的选择发生变化时,代码会检查Ctrl按钮,这对于检测正常物理键的Ctrl键很有效,但是当我使用屏幕键盘并按下Ctrl键时,它不会在我的程序中注册。 The root of this code is that you cannot Ctrl+Click the rows in a Datagrid in WPF when you use the Ctrl key of the on screen keyboard. 此代码的根目录是,当您使用屏幕键盘的Ctrl键时,无法按Ctrl +单击WPF中的Datagrid中的行。

Edit: It seems to satisfy the if condition if, on the on screen keyboard, I press ctrl and then "A" (which selects all). 编辑:似乎满足if条件,如果在屏幕键盘上,我按ctrl然后按“A”(选择全部)。 None of the other shortcuts (ctrl+c, ctrl + v trigger this response) 没有其他快捷方式(ctrl + c,ctrl + v触发此响应)

I ended up coding around the problem and added a check box to every row in the datagrid. 我最终围绕问题进行了编码,并在数据网格中的每一行都添加了一个复选框。 Although this no longer allows for the use of ctrl+click and shift+click the selection mechanics works just as well as it does on a touch screen as it does on a physical keyboard. 虽然这不再允许使用ctrl + click和shift + click,但选择机制的工作方式与在触摸屏上的工作方式相同,就像在物理键盘上一样。 I hope eventually the on screen keyboard will be more full featured and have less "bugs". 我希望屏幕键盘最终会更全面,并且有更少的“错误”。

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

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