Page 1 of 1

A problem with getasynckeystate

Posted: Tue May 29, 2012 12:59 pm
by anthonygz
Hello fellow Codenstuff members, i made this topic today to possibly get some help from you.


Here is the error i keep getting:

GetAsyncKeyState' has unbalanced the stack.


Here is the error ed code:

If (GetAsyncKeyState(113)) Then






sorry for wasting your time but i just don't get what i'm doing wrong, it used to work before.


Edit:
sorry here's the full error

PInvokeStackImbalance was detected
Message: A call to PInvoke function 'MouseRecord!MouseRecord.Form1::GetAsyncKeyState' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

Edit:
What i'm thinking is that 2010 doesn't support it and i need 2008.



OS: Vista

Re: A problem with getasynckeystate

Posted: Tue May 29, 2012 1:35 pm
by CodenStuff
Should be:
Code: Select all
GetAsyncKeyState((113))
Or you can just use the key name:
Code: Select all
GetAsyncKeyState(Keys.F2)

Re: A problem with getasynckeystate

Posted: Tue May 29, 2012 6:32 pm
by MrAksel
Its nothing to do with version of VB or your OS. Neither will Cody's code help. You should declare it like this:
Code: Select all
    <DllImport("user32.dll")> _
     Public Shared Function GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys) As Short
     End Function