问题描述
我目前工作的需要根据用户是否presses向右或向左shift键(RShiftKey,LShiftKey)不同的行为的应用程序,然而,当其中任何一个键是pressed我只看到Shift键|转变。
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...
这是一个pretty的,此刻大问题,因为没有办法测试了code ++工程(除单元测试)。任何人有不同的移位/ 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和诊断:
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");
}
}
}
这篇关于右移和左移键之间。净差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!