VB.NET Hotkey problem

Posts 15 of 5 · Page 1 of 1
VB.NET Hotkey problem
Trying to add hotkeys to my next release

Code:
        Dim F9P As Boolean
        Dim F10P As Boolean
        F9P = GetAsyncKeyState(Keys.F9)
        F10P = GetAsyncKeyState(Keys.F10)
Error:

Code:
PInvokeStackImbalance was detected
Message: A call to PInvoke function 'NinjaStormNSs Crosshair!NinjaStormNSs_Crosshair.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.

I already declared GetAsyncKeyState
Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
So?..
Make a timer with delay of 1 millisecond and activated for check if hotkey get clicked
Write:
Code:
  Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        If (GetAsyncKeyState(&H71)) Then
         'what will happen
                    End If
(&H71 = F2, google for others)

and add

Code:
   <DllImport("user32.dll")> _
    Public Shared Function GetAsyncKeyState(ByVal vKey As Int32) As Short
    End Function

    <DllImport("user32.dll")> _
    Public Shared Function GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys) As Short
    End Function
Quote Originally Posted by xKickAss View Post
Make a timer with delay of 1 millisecond and activated for check if hotkey get clicked
Write:
Code:
  Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        If (GetAsyncKeyState(&H71)) Then
         'what will happen
                    End If
(&H71 = F2, google for others)

and add

Code:
   <DllImport("user32.dll")> _
    Public Shared Function GetAsyncKeyState(ByVal vKey As Int32) As Short
    End Function

    <DllImport("user32.dll")> _
    Public Shared Function GetAsyncKeyState(ByVal vKey As System.Windows.Forms.Keys) As Short
    End Function
Just the guy I needed, Thanks it worked fine.

oh and I also had to import this:
Code:
Imports System.Runtime.InteropServices
Thanks again
Used to get this too Someone told me you have to change "Integer" to "UInteger" but that never worked. Glad you fixed it though
Quote Originally Posted by Katy View Post
Used to get this too Someone told me you have to change "Integer" to "UInteger" but that never worked. Glad you fixed it though
Would love to see some hotkeys in your next release
Posts 15 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?