且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查找用户是否按下某个键?

更新时间:2023-12-02 23:53:34

您需要为您感兴趣的每个键检查 GetAsyncKeyState.在这种情况下,您将检查 F10,然后检查shift、ctrl、alt 等.请参阅虚拟密钥代码 有关可能的值,请参阅 获取AsyncKeyState.

You need to check GetAsyncKeyState for each key you're interested in. In this case you will check for F10 and then check for shift, ctrl, alt and others. See virtual key codes for the possible values and see GetAsyncKeyState.

short key = GetAsyncKeyState(Keys.F10);
// Check the most significant bit to see if the key is down
if ( ( key & 0x8000 ) > 0 )
{
     // Check  shift is down 0x10 is value for VK_SHIFT
     key = GetAsyncKeyState( 0x10 );
     if ( key & 0x8000 ) > 0 )
     {
         // Shift key is down as well
     }
     // Repeat for other key states.
}

看c#keys enumeration 有许多可能的移位值,您可能需要尝试一下.

Looking at the c# keys enumeration there are number of possible values for shift, you might need to experiment a bit.