.net右移键和左移键之间的区别

.net difference between right shift and left shift keys(.net右移键和左移键之间的区别)
本文介绍了.net右移键和左移键之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个应用程序,该应用程序需要根据用户是按下右移键还是左移键(RShiftKey、LShiftKey)而需要不同的行为,但是当按下这些键中的任何一个时,我只能看到 ShiftKey |换档.

I am currently working on an application which requires different behaviour based on whether the user presses the right or left shift key (RShiftKey, LShiftKey), however when either of these keys is pressed I only see ShiftKey | Shift.

我的键盘有问题吗?(笔记本电脑)我是否需要一个新的键盘驱动程序/键盘才能发送不同的键盘命令...

Is there something wrong with my keyboard? (laptop) do I need a new keyboard driver/keyboard in order to send the different key commands maybe...

目前这是一个相当大的问题,因为没有办法测试代码是否有效(除了单元测试).有人对不同的 shift/alt/ctrl 键有任何经验吗?

This is a pretty massive problem at the moment, as there is no way of testing that the code works (apart from unit tests). Anyone had any experience of the different shift/alt/ctrl keys?

推荐答案

我不知道这篇文章是否对你有帮助,但看起来你可能不得不搞砸 InteropServices 和 Diagnostics:

I don't know if this post will help you or not, but it looks like you may have to mess with InteropServices and Diagnostics:

MSDN 论坛:如何发送左/右shift键

我终于弄明白了如何让 GetAsyncKeyState() 工作,正如 adrianbanks 透露的那样.

I finally figured out how to make GetAsyncKeyState() work, as adrianbanks revealed.

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern short GetAsyncKeyState(Keys vKey);

private void theForm_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.ShiftKey)
    {
        if (Convert.ToBoolean(GetAsyncKeyState(Keys.LShiftKey)))
        {
            Console.WriteLine("Left");
        }
        if (Convert.ToBoolean(GetAsyncKeyState(Keys.RShiftKey)))
        {
            Console.WriteLine("Right");
        }
    }
}

这篇关于.net右移键和左移键之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)