причина ошибки вы описали потому, что имя функции GetAsyncKeyState, не GetAsncKeyState.
Также в .NET вы должны рассмотреть, чтобы использовать атрибут DllImport
вместо Declare
заявления (которое является устаревшим VB6 стильным методологии) к provide more control over how platform invoke functions are called.
Вот ниже GetAsyncKeyState
декларации that I use, с включенными XML документация:
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Determines whether a key is up or down at the time the function is called,
''' and whether the key was pressed after a previous call to <see cref="GetAsyncKeyState"/>.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <remarks>
''' <see href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx"/>
''' </remarks>
''' ----------------------------------------------------------------------------------------------------
''' <param name="vKey">
''' The virtual-key code.
''' <para></para>
''' You can use left- and right-distinguishing constants to specify certain keys.
''' <para></para>
''' See Virtual-Key Codes:
''' <see href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx"/>
''' </param>
''' ----------------------------------------------------------------------------------------------------
''' <returns>
''' If the function succeeds,
''' the return value specifies whether the key was pressed since the last call to <see cref="GetAsyncKeyState"/>,
''' and whether the key is currently up or down.
''' <para></para>
''' If the most significant bit is set, the key is down, and if the least significant bit is set,
''' the key was pressed after the previous call to <see cref="GetAsyncKeyState"/>.
''' <para></para>
''' However, you should not rely on this last behavior.
''' <para></para>
''' <para></para>
''' The return value is zero for the following cases:
''' <para></para>
''' The current desktop is not the active desktop.
''' <para></para>
''' The foreground thread belongs to another process and the desktop does not allow the hook or the journal record.
''' </returns>
''' ----------------------------------------------------------------------------------------------------
<SuppressUnmanagedCodeSecurity>
<DllImport("user32.dll", CharSet:=CharSet.Auto)>
Public Shared Function GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys
) As Short
End Function
Примечание: Вы можете изменить параметр vKey
для Integer
типа данных, если вы preffer.
Я использую фреймворк 3.5, visualstudio 2010 – user5353093
Любопытно, как вы ошиблись, объясните, как это произошло. –
@HansPassant верен, имя ошибочно ... – Codexer