我可以确定Ctrl键preSS是左Ctrl键或右Ctrl?Ctrl、preSS

2023-09-04 00:50:12 作者:余生半杯酒

我要确定一个Ctrl键是左Ctrl键或右Ctrl键时,它是pssed $ P $。我怎样才能做到这一点?

I want to determine whether a Ctrl key is left Ctrl or right Ctrl key when it is pressed. How can I do this?

推荐答案

AFAIK你不能从.NET中访问这些信息。

AFAIK you can't access this information from within .net.

不过,您可以使用Win32 API GetAsyncKeyState 来测试是否特定的键是目前下跌,这样就可以区分左,右Ctrl键。 (如果你正在编写一个游戏,这是更可能很好地帮助你比的keydown的处理程序,如GetAsyncKeyState测试是否该键被按下现在,而不是它是否是pressed在过去的一段时间,这给相当好的响应)。

However, you can use the Win32 API GetAsyncKeyState to test if specific keys are currently down, and this can differentiate the left and right ctrl keys. (If you're writing a game this is more likely to work well for you than Keydown handlers, as GetAsyncKeyState tests whether the key is down "now" rather than whether it was pressed "at some time in the past", which gives considerably better responsiveness).