2013-04-11 199 views
-1
[DllImport("user32.dll")] 
    public static extern short GetAsyncKeyState(UInt16 virtualKeyCode); 

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

     } 
    } 
} 

我不斷收到一個錯誤,提示「名稱'VK_LBUTTON'在當前上下文中不存在」。任何幫助將非常感激。GetAsyncKeyState VK_LBUTTON。名稱在當前上下文中不存在

回答

0

使用以下代碼。

[DllImport("user32.dll")] 
publicstaticexternshort GetAsyncKeyState(UInt16 virtualKeyCode); 
privateconstUInt16 VK_MBUTTON = 0×04;//middle mouse button 
privateconstUInt16 VK_LBUTTON = 0×01;//left mouse button 
privateconstUInt16 VK_RBUTTON = 0×02;//right mouse button 

更多細節 http://msdn.microsoft.com/en-us/library/dd375731(v=VS.85).aspx

+0

我現在有[的DllImport( 「USER32.DLL」)] 公共靜態外部短GetAsyncKeyState(UINT16 virtualKeyCode); private const UInt16 VK_LBUTTON = 0x01; 私人無效timer1_Tick(對象發件人,EventArgs的) { 如果(GetAsyncKeyState(VK_LBUTTON))//這是突出顯示的錯誤 { MessageBox.Show( 「測試」); }} } } 和 它說: 「不能imlicitly轉換型 '短' 爲 '布爾'」 – Moe 2013-04-11 10:59:11

+0

你可以這樣做,如果((布爾)GetAsyncKeyState(VK_LBUTTON)) – abhi294074 2013-04-11 11:12:47

+0

作品。非常感謝!!! – Moe 2013-04-11 11:32:02

相關問題