问题描述
我目前正在开发一个应用程序,该应用程序需要根据用户是按下右移键还是左移键(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右移键和左移键之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)