I have some error in the following loop and I don't know what it is since it doesn't return any error, it just hangs..
While GetKeyState(Keys.Insert).ToString <> "-127" Or GetKeyState(Keys.Insert).ToString <> "-128"
If GetKeyState(Keys.Insert).ToString = "-127" Or GetKeyState(Keys.Insert).ToString = "-128" Then
PosMouse.Text = "OK"
Exit Sub
End If
End While
I have 2 programs: listen.exe and main.exe
Pressing a button in the listen.exe program will trigger the loop, so that when "INSERT" is pressed in the main.exe program, the mouse position will be recorded.
So later I can move the mouse to that position.
I got out of trouble with a timer but I'm curious about the solution...
Greetings and thank you very much!
The problem with that loop is that it might block the ui, so the form's events aren't processed, so the keystroke will never actually be read.
A very simple solution to check if that is it is to put a
Application.DoEvents()
inside the loop:But the normal thing is that this code is in another thread, using
BackGroundWorker
orTask