Use the Activated and Deactivate events of your main form...
Something like this:
Public Class MainForm
Private hasFocus As Boolean = False
Private Sub MainForm_Activated(sender As Object, e As EventArgs) Handles MyBase.Activated
hasFocus = True
End Sub
Private Sub MainForm_Deactivate(sender As Object, e As EventArgs) Handles MyBase.Deactivate
hasFocus = False
End Sub
End Class
Good luck!