C# GetAsyncKeyState VK_LBUTTON。名称在当前上下文中不存在

C# GetAsyncKeyState VK_LBUTTON。名称在当前上下文中不存在,c#,visual-studio,C#,Visual Studio,我不断收到一个错误,说“名称'VK_LBUTTON'在当前上下文中不存在”。任何帮助都将不胜感激。请使用以下代码 [DllImport("user32.dll")] public static extern short GetAsyncKeyState(UInt16 virtualKeyCode); private void timer1_Tick(object sender, EventArgs e) { if (GetAsyncKeySta

我不断收到一个错误,说“名称'VK_LBUTTON'在当前上下文中不存在”。任何帮助都将不胜感激。

请使用以下代码

    [DllImport("user32.dll")]
    public static extern short GetAsyncKeyState(UInt16 virtualKeyCode); 

    private void timer1_Tick(object sender, EventArgs e)
    {
        if (GetAsyncKeyState(VK_LBUTTON = 0x01))
        {

        }
    }
}
更多细节

我现在有[dlliport(“user32.dll”)]公共静态外部短GetAsyncKeyState(UInt16 virtualKeyCode);私有const UInt16 VK_LBUTTON=0x01;private void timer1_Tick(object sender,EventArgs e){if(GetAsyncKeyState(VK_LBUTTON))//这是突出显示的错误{MessageBox.Show(“test”);}}}}}},它说“无法正确地将类型'short'转换为'bool'”,您可以这样做,如果((bool)GetAsyncKeyState(VK_LBUTTON))
[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(UInt16 virtualKeyCode);
private const UInt16 VK_MBUTTON = 0x04;//middle mouse button
private const UInt16 VK_LBUTTON = 0x01;//left mouse button
private const UInt16 VK_RBUTTON = 0x02;//right mouse button