Windows 7 x64上的GetAsyncKeyState

Evr*_*urk 0 c# pinvoke c#-2.0

我试图在带有C#的windows7 x64上使用GetAsyncKeyState(i)来获取按键.它在x86上运行完美.这是我的代码:

[DllImport("user32.dll")]
public static extern int GetAsyncKeyState(long vKey);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
public static extern short GetKeyState(int keyCode); 

        search = false;
        int key_my;
        for (i = 0; i < 255; i++)
        {
            key_my = GetAsyncKeyState(i); // this should return -3.... but it does 46...........
            if ( key_my == (System.Int16.MinValue + 1))
            { search = true; break; }
        }
        if ( search == true)
        {
           ...//using if to keys here.
        }
Run Code Online (Sandbox Code Playgroud)

任何的想法?

Jar*_*Par 5

GetAsyncKeyState函数的返回类型应为shortnot,int并且应将其参数键入为intnotlong

[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(int vKey);
Run Code Online (Sandbox Code Playgroud)