右移和左移键之间。净差 [英] .net difference between right shift and left shift keys

查看:336
本文介绍了右移和左移键之间。净差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的需要根据用户是否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:

<一个href="http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/dd6406e8-b6bf-4166-82a0-6d533def38a5"相对=nofollow> 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");
        }
    }
}

这篇关于右移和左移键之间。净差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆