I have the following codes:

Code:

Public Class uiKeyLogger
    <Flags()> _
Private Enum SHOW_WINDOW As Integer
        SW_HIDE = 0
        SW_SHOWNORMAL = 1
        SW_NORMAL = 1
        SW_SHOWMINIMIZED = 2
        SW_SHOWMAXIMIZED = 3
        SW_MAXIMIZE = 3
        SW_SHOWNOACTIVATE = 4
        SW_SHOW = 5
        SW_MINIMIZE = 6
        SW_SHOWMINNOACTIVE = 7
        SW_SHOWNA = 8
        SW_RESTORE = 9
        SW_SHOWDEFAULT = 10
        SW_FORCEMINIMIZE = 11
        SW_MAX = 11
    End Enum

    Dim result As Integer
    Dim boolExist As Boolean = False
    Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
    Private Declare Function ShowWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nCmdShow As SHOW_WINDOW _
) As Boolean

    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) 'gets the key state

            If result = -32767 Then 'if a known key is pressed, it will be displayed in the textbox1
                If Chr(i) = "t" Then
                    For Each p As Process In Process.GetProcessesByName("CashReceipt")
                        ShowWindow(p.MainWindowHandle, SHOW_WINDOW.SW_RESTORE)
                        boolExist = True
                    Next p

                    If boolExist = False Then
                        Process.Start("C:\Users\cmchong\Desktop\TFS_CASH_RECEIPT\CashReceipt.exe")
                    End If

                    boolExist = False
                End If
            End If
        Next i

    End Sub

    Private Sub uiKeyLogger_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        btnStart_Click(sender, New EventArgs())
    End Sub

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        ShowInTaskbar = False
        Timer1.Enabled = True
        Me.Hide()
    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
        End
    End Sub
End Class

Unfortunately, this codes will always restore the external application. How can I amend the codes if the external application was restore, it will be minimize or if the application was minimized, then it will be restored.