This is really starting to frustrate me.
Basically, this is part of a script I am coding for GTA IV (when it's done I might publish the mod on my website) and I need to exit this loop when the user presses a defined key in-game. Of course, I can't use KeyPreview because this is a class library (GTA IV plugins have to use .net.dll).
Here is what I have tried so far (obviously not the full code), as suggested on numerous websites:
Loop:
Sub CarFunctions()
    Dim veh = Player.Character.CurrentVehicle
    Do
        Application.DoEvents()
        If CancelLoop = True Then
            Exit Do
        End If
        Native.Function.Call("SET_VEH_INDICATORLIGHTS", veh, True)
        Native.Function.Call("FORCE_CAR_LIGHTS", veh, 1)
        Wait(500)
        Native.Function.Call("SET_VEH_INDICATORLIGHTS", veh, False)
        Native.Function.Call("FORCE_CAR_LIGHTS", veh, 2)
        Wait(500)
    Loop
End Sub
KeyDown Event:
Private Sub VehicleControls_KeyDown(sender As Object, e As GTA.KeyEventArgs) Handles Me.KeyDown
    Try
        Dim veh = Player.Character.CurrentVehicle
        If e.Key = Keys.NumPad5 Then
            CancelLoop = True
        End If
    Catch ex As Exception
        Game.Console.Print(ex.ToString)
    End Try
End Sub
The problem, I know, is that the program does not detect any keypress events while it is in a loop. I tried to use multithreading, but it throws an exception in the game and I cannot use an invoke method.
Thank you in advance.
 
     
    