Recording Keys

Posts 1–4 of 4 · Page 1 of 1
Recording Keys
Kinda like a key logger but not the purpose something more legal. I am making a mw2 rage quit program. In the program You have to bind a button to rage quit. So obviously I first tried a key-logger source.
Code:
 Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Declare Function GetKeyState Lib "user32" (ByVal vKey As Long) As Integer


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        For i = 1 To 255
            result = 0
            result = GetAsyncKeyState(i)
            If result = -32767 Then
                TextBox1.Text = Chr(i)
            End If
        Next i
    End Sub
Don't hate me. But then I get a MDA error
Code:
PInvokeStackImbalance was detected
Message: A call to PInvoke function 'recording keys!recording_keys.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.
How do I correct this program.
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Int32) As Int16
That error happens to me while debugging, But if i open the program directly it doesnt have any problems..
umm

[highlight=vb]
'///Did this in my head so correct me if I'm wrong///
Dim result As Integer
Dim key As String
Dim i As Integer
For i = 2 To 90
result = 0
result = GetAsyncKeyState(i)
If result = -32767 Then
key = Chr(i)
If i = 13 Then
key = vbNewLine
Exit For
End If
End If
Next i
[/highlight]

if your trying to make custom hotkeys you do have to make it stop recording it's basically a full keylogger but that should get ride of the error

Plus you still have to declare that the next key pressed is the hotkey string Good luck
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us